apollo-server/packages/apollo-server-micro/README.md

36 lines
1.4 KiB
Markdown
Raw Normal View History

---
title: Micro
description: Setting up Apollo Server with Micro
---
[![npm version](https://badge.fury.io/js/apollo-server-core.svg)](https://badge.fury.io/js/apollo-server-core) [![Build Status](https://travis-ci.org/apollographql/apollo-server.svg?branch=master)](https://travis-ci.org/apollographql/apollo-server) [![Coverage Status](https://coveralls.io/repos/github/apollographql/apollo-server/badge.svg?branch=master)](https://coveralls.io/github/apollographql/apollo-server?branch=master) [![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://www.apollographql.com/#slack)
2017-05-24 00:29:15 -06:00
This is the [Micro](https://github.com/zeit/micro) integration for the Apollo community GraphQL Server. [Read the docs.](https://www.apollographql.com/docs/apollo-server/) [Read the CHANGELOG.](https://github.com/apollographql/apollo-server/blob/master/CHANGELOG.md)
```sh
npm install apollo-server-micro
```
2017-05-24 00:29:15 -06:00
## Example
```js
import { microGraphiql, microGraphql } from 'apollo-server-micro';
import micro, { send } from 'micro';
import { get, post, router } from 'microrouter';
import schema from './schema';
2017-05-24 00:29:15 -06:00
2017-06-05 15:58:10 -06:00
const graphqlHandler = microGraphql({ schema });
const graphiqlHandler = microGraphiql({ endpointURL: '/graphql' });
2017-05-24 00:29:15 -06:00
const server = micro(
router(
get('/graphql', graphqlHandler),
post('/graphql', graphqlHandler),
get('/graphiql', graphiqlHandler),
(req, res) => send(res, 404, 'not found'),
),
2017-05-24 00:29:15 -06:00
);
server.listen(3000);
```