Skip to main content
Case Studies
Apollo Koa Implementation for a Multi Tenant GraphQL API

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.

Choose Your Koa Stack

As a developer, you should decide how you want to use the Koa middleware stack. For that reason, we only include the bare minimum so that you can choose how you want to do body parsing or if you want to expose the GraphQL playground. You are in control.

Getting Started

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

Simple GraphQL Server Example

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.