Package Exports
- graphql-api-koa
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (graphql-api-koa) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
graphql-api-koa
GraphQL API Koa middleware.
Setup
Install with peer dependencies using npm:
npm install graphql-api-koa graphqlAPI
Table of Contents
errorHandler
Creates Koa middleware to handle errors. Use this middleware first to catch all errors for a correctly formated GraphQL response. For security, errors thrown outside resolvers without an expose property and true value are masked by a generic 500 error.
Examples
A basic GraphQL API.
import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import { errorHandler, execute } from 'graphql-api-koa'
import schema from './schema'
const app = new Koa()
.use(errorHandler())
.use(bodyParser())
.use(execute({ schema }))Returns Function Koa middleware.
execute
Creates Koa middleware to execute GraphQL. Use after the errorHandler and body parser middleware.
Parameters
optionsExecuteOptions Options.
Returns Function Koa middleware.
Types
The following types are for documentation only and are not exported.
ExecuteOptions
GraphQL execute Koa middleware options.
Type: Object
Properties
schemamodule:graphql.GraphQLSchema GraphQL schema.rootValueany? Value passed to the first resolver.contextValueany? Execution context (usually an object) passed to resolvers.fieldResolverFunction? Custom default field resolver.overrideMiddlewareOptionsOverride? Override any ExecuteOptions (exceptoverride) per request.
MiddlewareOptionsOverride
Per-request Koa middleware options override.
Type: Function
Parameters
contextmodule:koa.Context Koa context.
Examples
execute middleware options setting the schema once at startup and user context per-request.
import schema from './schema'
const executeOptions = {
schema,
override: ctx => ({
contextValue: {
user: ctx.user
}
})
}Returns Object Options.