GQLExpressMiddleware

GQLExpressMiddleware

new GQLExpressMiddleware()

A handler that exposes an express middleware function that mounts a
GraphQL I/O endpoint. Typical usage follows:

const app = express();
app.use(/.../, new GQLExpressMiddleware([...classes]).middleware);
Source:

Classes

⎆⠀constructor

Members

ast

The schema property returns the textual Schema as it is generated based
on the various Lattice types, interfaces and enums defined in your
project. The ast property returns the JavaScript AST represenatation of
that schema with all injected modificiations detailed in your classes.

Source:

Methods

(static) clearCache() → {GQLExpressMiddleware}

The Schema String and Schema AST/GraphQLSchema JavaScript objects are
cached after being processed once. If there is a runtime need to rebuild
these objects, calling clearCache() will allow their next usage to
rebuild them dynamically.

Source:
Returns:
Type:
GQLExpressMiddleware

returns this so that it can be inlined; ala
gqlExpressMiddleware.clearCache().ast, for example

(static) ⌾⠀generateSchemaSDL() → {string}

A function that combines the IDL schemas of all the supplied classes and
returns that value to the middleware getter.

Source:
Returns:
Type:
string

a dynamically generated GraphQL IDL schema string

astMiddleware() → {function}

An optional express middleware function that can be mounted to return
the JSON AST representation of the schema string being used by
GQLExpressMiddleware.

Source:
Returns:
Type:
function

generateApolloOptions(options, patchFn)

In order to ensure that Lattice functions receive the request data,
it is important to use the options function feature of both
express-graphql and apollo-server-express. This function will create
an options function that reflects that schema and Lattice types defined
in your project.

Should you need to tailor the response before it is sent out, you may
supply a function as a second parameter that takes two parameters and
returns an options object. The patchFn callback signature looks like this

patchFn(options, {req, res, next|gql})

When using the reference implementation, additional graphql request info
can be obtained in lieu of the next() function so typically found in
Express middleware. Apollo Server simply provides the next function in
this location.

Source:
Parameters:
Name Type Default Description
options Object

any options, to either engine, that make the most
sense

patchFn function null

see above

generateOptions(options, patchFn)

In order to ensure that Lattice functions receive the request data,
it is important to use the options function feature of both
express-graphql and apollo-server-express. This function will create
an options function that reflects that schema and Lattice types defined
in your project.

Should you need to tailor the response before it is sent out, you may
supply a function as a second parameter that takes two parameters and
returns an options object. The patchFn callback signature looks like this

patchFn(options, {req, res, next|gql})

When using the reference implementation, additional graphql request info
can be obtained in lieu of the next() function so typically found in
Express middleware. Apollo Server simply provides the next function in
this location.

Source:
Parameters:
Name Type Default Description
options Object

any options, to either engine, that make the most
sense

patchFn function null

see above

schemaMiddleware() → {function}

An optional express middleware function that can be mounted to return
a copy of the generated schema string being used by GQLExpressMiddleware.

Source:
Returns:
Type:
function

⌾⠀customMiddleware(graphqlHttpOptionsopt, patchFn) → {function}

If your needs require you to specify different values to graphqlHTTP,
part of the express-graphql package, you can use the customMiddleware
function to do so.

The first parameter is an object that should contain valid graphqlHTTP
options. See https://github.com/graphql/express-graphql#options for more
details. Validation is NOT performed.

The second parameter is a function that will be called after any options
have been applied from the first parameter and the rest of the middleware
has been performed. This, if not modified, will be the final options
passed into graphqlHTTP. In your callback, it is expected that the
supplied object is to be modified and THEN RETURNED. Whatever is returned
will be used or passed on. If nothing is returned, the options supplied
to the function will be used instead.

Source:
Parameters:
Name Type Attributes Default Description
graphqlHttpOptions Object <optional>
{graphiql: true}

standard set of
express-graphql options. See above.

patchFn function

see above

Returns:
Type:
function

a middleware function compatible with Express

⬇︎⠀middleware() → {function}

Using the express-graphql module, it returns an Express 4.x middleware
function.

Source:
Returns:
Type:
function

a function that expects request, response and next
parameters as all Express middleware functions.

⬇︎⠀middlewareWithoutGraphiQL() → {function}

Using the express-graphql module, it returns an Express 4.x middleware
function. This version however, has graphiql disabled. Otherwise it is
identical to the middleware property

Source:
Returns:
Type:
function

a function that expects request, response and next
parameters as all Express middleware functions.

⬇︎⠀schema() → {string}

Generates the textual schema based on the registered GQLBase handlers
this instance represents.

Since:
  • 2.7.0
Source:
Returns:
Type:
string

a generated schema string based on the handlers that
are registered with this GQLExpressMiddleware instance.