0.0.1 • Published 8 years ago

micro-graphql v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

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.js

Documentation

Installation

Install from NPM:

$ npm install micro-graphql --save

API

createHandler

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 schema
  • root can be anything, and is the root value of your executed query
  • formatError is a function which allows custom error formatting; defaults to graphql-js#formatError
  • This function is exposed as the default export.
  • Returns a micro request handler which 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)
}