5.1.1 • Published 4 years ago

@koikorn/app-schema-router v5.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

GraphQL Schema Router

View changelog

A KeystoneJS App that route requests to different GraphQL schemas.

The SchemaRouterApp allows you to define a routerFn which takes (req, res) and returns a routerId, which is used to pick between different GraphQL schemas which exist at the same apiPath.

Usage

const { Keystone } = require('@koikorn/keystone');
const { GraphQLAppPlayground } = require('@koikorn/app-graphql-playground');
const { SchemaRouterApp } = require('@koikorn/app-schema-router');
const { GraphQLApp } = require('@koikorn/app-graphql');
const { AdminUIApp } = require('@koikorn/app-admin-ui');

module.exports = {
  keystone: new Keystone(),
  apps: [
    new GraphQLAppPlayground({ apiPath })
    new SchemaRouterApp({
      apiPath,
      routerFn: (req) => req.session.keystoneItemId ? 'private' : 'public',
      apps: {
        public: new GraphQLApp({ apiPath, schemaName: 'public', graphiqlPath: undefined }),
        private: new GraphQLApp({ apiPath, schemaName: 'private', graphiqlPath: undefined }),
      },
    }),
    new AdminUIApp()
  ],
};

Config

OptionTypeDefaultDescription
apiPathString/admin/apiThe GraphQL API path
routerFnFunction() => {}A function which takes (req, res) and returns a routerId
appsObject{}An object with routerIds as keys and GraphQLApps as values