GraphQL: Apollo Server Plugins in Typescript

We’re using GraphQL, and leveraging the Apollo project’s server and client platform to rapidly prototype and deploy a Node GraphQL server. Apollo has been fantastic, I’ll post separately about the technical ...

Follow me here, or on Twitter @jmagnuss as I plan to document the journey from architecture to implementation of this new mobile bank on AWS…

We’re using GraphQL, and leveraging the Apollo project’s server and client platform to rapidly prototype and deploy a Node GraphQL server. Apollo has been fantastic, I’ll post separately about the technical decisions that led us through a few options to land on Apollo, and why it’s the best choice for a secure, flexible GraphQL implementation that lets our developers move rapidly.

Apollo Server Plugins

As part of this work, I have plans for some Apollo Server plugins, to handle things like idempotency on requests, and look forward to releasing those publicly. Unfortunately, the (generally really excellent) Apollo documentation around plugins is all in functional Javascript, where we’re making every effort to live in Typescript to gain the safety nets of strong typing.

Here’s the Apollo Server documentation on Plugins

I wasn’t able to find a simple example of a Typescript plugin class, so I’ve written a working one here that you can copy and paste to fill in the methods you need.

Apollo exposes a base interface, ApolloServerPlugin that handles two triggers, but the requestDidStart callback also returns a GraphQLRequestListener that handles another seven triggers. I’ve combined both into a single class, with typing, and shown logging to output the important context data at each lifecycle stage.

Copy it, use it, and ping me if you find it valuable!


If you want to see how the full Apollo Server Idempotency plugin ends up, follow me here and on twitter…

https://twitter.com/jmagnuss

Some resources:

A simple, functional typescript plugin for blocking requests with too much GraphQL complexity

An Apollo middleware plugin in Typescript to integrate Sentry error monitoring.



I’m working with a team to build a new mobile bank for unbanked female entrepreneurs, and busy building towards a proof-of-concept to prove out the technology decisions as we move towards a pilot later in 2020.

More Recent Stories.