What I learned about GraphQL and Make

What I learned about GraphQL and Make

If you haven’t learned about GraphQL or have struggled with trying to get your GraphQL server to send back data, fear not.

Learn GraphQL.

Learn how it works from graphql.org and try the Star Wars GraphQL API StarWars GraphQL API. You won’t be sorry. It’s incumbent that you understand what GraphQL is: it is a Query Langauge (QL) for a graph. Here’s a pictorial representation of the StarWars Graph

It is very different from REST because you mostly use POST to send data via JSON and there is only 1 endpoint to query data from the graph. (Mutations modify the data model and subscriptions get real time updates but I won’t cover that here).

GraphQL Docs/Explorer

Make sure you have access to the GraphQL Docs/Explorer for your API. Without that doing some experiments will be very hard and you won’t be able to model your queries the way you want them to.

The data is returned in the “shape” you want it

GraphQL returns your data in the “shape” you want it to - you can query multiple objects, set filters, page and create joined data between multiple objects with one call. Instead of calling multiple REST API calls, GraphQL usually can return all the data you need in the way you need it with just 1 call. This is primarily the reason why Facebook invented it in 2012. It’s been around since 2015 as an open source project so not many APIs use it but some definitely have adopted GraphQL as an alternative and some support GraphQL as the only API architecture.

Gotchas

The HTTP module is very persnickety when it comes to the JSON payload. GraphQL data has carriage returns sometimes in the Explorer but Make doesn’t always like that and returns invalid JSON error before it even attempts to run the payload. Eliminate carriage returns and make sure any double quotes (") are escaped with a \"

Here’s a short little video of what I learned.

And here is the scenario that you can view and clone into your own Make account to experiment.

Once I get mutations working (creating & updating data in the model with GraphQL) I’ll update this post

7 Likes