Create a performant graphql server with micro and graphql-js
Create a performant graphql server with micro and graphql-js.
// server.js
import createHandler from 'micro-graphql'
import schema from './schema'
export default createHandler({ schema })
$ micro -p 3000 server.js
Install from NPM:
$ npm install micro-graphql --save
createHandler({ schema, context = null, root = null, formatError = defaultFormatError })
schema
is a non-optional instance of GraphQLSchema
from graphql-js
context
can be anything, and is passed to all resolve
functions in your schemaroot
can be anything, and is the root value of your executed queryformatError
is a function which allows custom error formatting; defaults to graphql-js#formatError
default
export.micro request handler
which executes GraphQL queries and responds with JSONexport default async (req, res) => {
const handler = createHandler({
schema,
context: { req }
})
return handler(req, res)
}