Apollo Koa Implementation for a Multi Tenant GraphQL API
This Apollo Koa implementation is created for our multi-tenant headless ecommerce service Crystallize. It is heavily inspired by apollo-server-koa but leverages koa’s middleware paradigm, thus making it easy to add path parameters, which is our preferred way of making our API multi-tenant. A feature like this was suggested for the official implementation several times, but since this didn’t seem to gain any traction, we implemented it ourselves and released it as open-source.
You can simply add this new GraphQL middleware via NPM to your project. You can also check out the koa middleware on GitHub, pull requests welcome.
yarn add @crystallize/koa-middleware-apollo
A basic example of a GraphQL server with this Koa middleware is shown below. This approach makes it easy to add things like authorization and authentication as part of the Koa stack. A more complete and involved example can be found in the project’s README.