mirror of
https://github.com/vale981/apollo-server
synced 2025-03-10 04:56:38 -04:00
35 lines
1.5 KiB
Markdown
35 lines
1.5 KiB
Markdown
---
|
|
title: Micro
|
|
description: Setting up Apollo Server with Micro
|
|
---
|
|
|
|
[](https://badge.fury.io/js/apollo-server-core) [](https://circleci.com/gh/apollographql/apollo-cache-control-js) [](https://coveralls.io/github/apollographql/apollo-server?branch=master) [](https://www.apollographql.com/#slack)
|
|
|
|
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
|
|
```
|
|
|
|
## Example
|
|
|
|
```js
|
|
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);
|
|
```
|