Skip to content

cpetzold/micro-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published