jasonfry.co.uk

GraphQL Getting Started

This Post

This post is not meant to be an extensive tutorial about GraphQL, it is a starting point for your own exploration into GraphQL that should give you several paths to go down and links to find out more. If you just read through this whole document in one go you will not have an understanding of GraphQL. Follow the links, try things out, and keep coming back to this page.

What is GraphQL

GraphQL is a language for querying data. With GraphQL, your existing services describe the data that they have, and clients describe the data they need.

It is often an alternative to RESTful APIs.

GraphQL started as a Facebook technology but is now part of its own foundation.

Why?

This is an old video from the early GraphQL days but the concepts are still true.

Getting Started

The GraphQL website has a simple tutorial to teach you GraphQL

https://graphql.org/learn/

A significant benefit of GraphQL is the client libraries and their ability to handle a significant chunk of your data layer for you. Apollo provide excellent client libraries that make caching almost effortless. If you make HTTP requests with an HTTP library (e.g. Axios, Alamofire) then you're missing out signifcantly.

Apollo also have some excellent GraphQL resources:

Building The Back-end

Apollo provide excellent Javascript /Node.js libraries:

https://www.apollographql.com/docs/apollo-server/getting-started/

There are various libraries for other languages as well, a popular one for Golang is gqlgen:

https://gqlgen.com/

Dataloader

Another common need in a backend is a 'Dataloader' - a utility to be used as part of your application’s data fetching layer to provide a consistent API over various backends (often databases) and reduce requests to those backends via batching and caching.

JS - https://github.com/graphql/dataloader

Golang - https://github.com/vektah/dataloaden

Federation / Stitching / Microservices

If you're using microservices and have several GraphQL services then you'll want to look into Apollo Federation which 'stitches' all of your services' graphs into one Graph. Federation is implemented in other GraphQL libraries too.

Designing Mutations

This article has some good design principles for building effective GraphQL mutation systems that can evolve over time:

https://dev-blog.apollodata.com/designing-graphql-mutations-e09de826ed97

Useful Tools

Insomnia is an HTTP and GraphQL client for debugging APIs https://insomnia.rest/

Learning More

https://graphqlweekly.com/ is a great email newsletter than sends you new articles and videos every week.