0.0.1 • Published 9 years ago
micro-graphql v0.0.1
Micro GraphQL
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.jsDocumentation
Installation
Install from NPM:
$ npm install micro-graphql --saveAPI
createHandler
createHandler({ schema, context = null, root = null, formatError = defaultFormatError })
schemais a non-optional instance ofGraphQLSchemafrom graphql-jscontextcan be anything, and is passed to allresolvefunctions in your schemarootcan be anything, and is the root value of your executed queryformatErroris a function which allows custom error formatting; defaults to graphql-js#formatError- This function is exposed as the
defaultexport. - Returns a
micro request handlerwhich executes GraphQL queries and responds with JSON - Tip: To configure the handler per-request, simply wrap it:
export default async (req, res) => {
const handler = createHandler({
schema,
context: { req }
})
return handler(req, res)
}0.0.1
9 years ago