express-graphql-schema-router
A package to route users to different GraphQL servers. Uses Express, ApolloServer, and graphql-http-proxy. Allows for custom filtering in each schema, and is reflected in what users see in GraphQL Playground.
Installation
npm i express-graphql-schema-router
schemaRouter({ entryPoints, path, router })
Options
entryPoints
: <Object>
(required)
- A map of ApolloServer options
path
: String
(required)
- Path to serve GraphQL from. Equates to
app.use(path, ...)
router
: <Function>
(required)
- Function which returns key of schema corresponding to ApolloServer options from
entryPoints
to route the response to
Example
const express = ;const jwt = ;const parseBearerToken = default;const schemaRouter = ; const app = ; ... const entryPoints = public: schema: publicSchema context authenticated: schema: authenticatedSchema context ; app; app;
filterSchemaRouter({ schemaMap, options, path, router })
Options
schemaMap
: <Object>
(required)
-
Map of schema keys to baseline and typeMap
-
typeMap
:<Object>
(default:{}
) -
baseline
:<Object>
(default:graylist
)
###### whitelist
Allow root fields, allow object fields
###### graylist
Deny root fields, allow object fields
###### blacklist
Deny root fields, deny object fields
-
Example:
public: baseline: graylist typeMap: Query: field1: true authenticated: baseline: whitelist
options
: <Object>
(required)
- A map of ApolloServer options
path
: String
(required)
- Path to serve GraphQL from. Equates to
app.use(path, ...)
router
: <Function>
(required)
- Function which returns key of schema corresponding to ApolloServer options from
entryPoints
to route the response to
Example
const express = ;const jwt = ;const parseBearerToken = default;const filterSchemaRouter whitelist graylist = ; const app = ; ... const publicTypeMap = Query: public1: true public2: true ; const schemaMap = public: baseline: graylist typeMap: publicTypeMap authenticated: baseline: whitelist ; app; app;
filterSchema({ schema, typeMap, baseline })
Filters fields available in a schema based on a typeMap and baseline. Returns the filtered schema.
Options
-
schema
: GraphQL Schema (required) -
typeMap
:<Object>
(default:{}
) -
baseline
:<Object>
(default:graylist
)