Production Apollo GraphQL - Essential Setup and Tooling

3 minute read

GraphQL has revolutionized the way we think about APIs, and Apollo has provided a suite of frameworks to get up and running quick and easy. We’ve been using GraphQL and Apollo since inception at the The Wed Clique. Since then I’ve learned the ins and outs of the Apollo GraphQL stack, and I’m here to share some tools I use supplement the relative immaturaty and get the stack to a place that’s a reliable production stack.

Machine readable errors with apollo-errors

The first headache you’ll encounter with the Apollo GraphQL stack is that errors returned to the client are in string format. An example:

apollo-errors example error

Pretty tough to do anything with that, right? Luckily thebigredgeek’s apollo-errors package is here to save us! All you have to do is plug it into your schema (a 1 line change), and now your errors looks like this:


Performance Insight with Apollo Engine

The beauty of nested GraphQL queries can also be its downfall if your resolvers aren’t structured correctly. Luckily we can use Apollo Engine to monitor each resolver for usage and quickly debug those long running queries. Check it out:

apollo engine metrics

Apollo Engine can do so much more, including caching and error tracking- all for free. Read this great post by Rohit Bakhshi of the Meteor team to learn more.

Query Context

Query context isn’t a tool, but something I rarely see use cases for in the multitude of “Hello World!” GraphQL posts. Context is a great place to inject request specific information that your resolvers can use. One quick use case is passing a current user variable for authorization:

If you’re using something like JWT for middleware, you can attach the context to each request like so:

And thats it!

If you enjoyed this article, please help out with a like, a share, or a comment. It fuels my focus to write more of it, thanks!

James Mensch is the Director of Engineering at Threatcare and the CEO at Magnifai. I believe in building intelligent products, using data to drive decisions, and engineering for social impact. I write about some of the cool stuff I do with tech, productivity and motivation psychology, and my social innovation projects. Connect with me on LinkedIn or say hi on Twitter.