Micro

Setting up Apollo Server with Micro

npm version Build Status Coverage Status Get on Slack

This is the Micro integration for the Apollo community GraphQL Server. Read the docs.

1
npm install apollo-server-micro

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { microGraphiql, microGraphql } from 'apollo-server-micro';
import micro, { send } from 'micro';
import { get, post, router } from 'microrouter';
import schema from './schema';

const graphqlHandler = microGraphql({ schema });
const graphiqlHandler = microGraphiql({ endpointURL: '/graphql' });

const server = micro(
router(
get('/graphql', graphqlHandler),
post('/graphql', graphqlHandler),
get('/graphiql', graphiqlHandler),
(req, res) => send(res, 404, 'not found'),
),
);

server.listen(3000);
Edit on GitHub