1.0.1 • Published 6 years ago

@keystone-alpha/app-schema-router v1.0.1

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

GraphQL Schema Router

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('@keystone-alpha/keystone');
const { GraphQLAppPlayground } = require('@keystone-alpha/app-graphql-playground');
const { SchemaRouterApp } = require('@keystone-alpha/app-schema-router');
const { GraphQLApp } = require('@keystone-alpha/app-graphql');
const { AdminUIApp } = require('@keystone-alpha/app-admin-ui');

module.exports = {
  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/apiChange the API path
routerFnFunction() => {}A function which takes (req, res) and returns a routerId
appsObject{}An object with routerIds as key and GraphQLApp as value