GraphQL is the rising star of backend technologies. It’s a popular alternative for REST as an API design paradigm and is becoming the new standard for exposing the data and functionality of a web server.
In this tutorial, you’ll learn how to build an idiomatic GraphQL server entirely from scratch.
You are going to use the following technologies:
fastify- a rising star in the HTTP servers ecosystem, very fast and efficient.
graphql-js- we will use the core
graphqllibrary as execution engine for our server.
graphql-helix- a collection of utility functions for building your own GraphQL HTTP server.
GraphiQL: A “GraphQL IDE” that allows you to interactively explore the functionality of a GraphQL API by sending queries and mutations to it. It’s somewhat similar to Postman which offers comparable functionality for REST APIs. Among other things, GraphiQL:
You can find the code of the tutorial in this repository.
The goal of this tutorial is to build an API for a HackerNews clone. Here is a quick rundown of what to expect.
You’ll start by learning the basics of how a GraphQL server works, simply by defining a GraphQL schema for the server and writing corresponding resolver functions. In the beginning, these resolvers will only work with data that’s stored in-memory - so nothing will persist beyond the runtime of the server.
Once you have the database connected, you are going to add more advanced features to the API.
You’ll start by implementing signup/login functionality that enables users to authenticate against the API. This will also allow you to check the permissions of your users for certain API operations.
Next, you’ll allow the consumers of the API to constrain the list of items they retrieve from the API by adding filtering and pagination capabilities to it.
Let’s get started 🚀