Scaleable GraphQL Architecture
Please follow me on Twitter, or come say hi on LinkedIn, and if you enjoy the article, please give it a clap — they lower my cholesterol 😃
GraphQL has been the new “In Thing” for a couple of years, but bigger companies are just starting to adopt it, and one of the first questions they ask is: how does it scale?
In my humble opinion, the answer is: it scales WAY better than REST.
The second question is often: ok, how do we scale it?
Here is my approach, which is somewhat simplistic, but extremely functional.
The only tools we’re going to use will be Apollo in the form of apollo-server-express, import statements and Template Literals. You should be able to use any of the Apollo Server modules in the same or a very similar way.
Function First vs Feature First
For a GraphQL API, the two main things you need are typeDefs
and resolvers
.
As the app grows, you can’t have them all in the same file — it simply gets too big, so how best to break them up?
There are two main approaches: function-first and feature-first.
Function-first means that you would have all the typeDefs
grouped together in one directory, and you’d have all the resolvers
grouped…