mirror of
https://github.com/vale981/apollo-server
synced 2025-03-16 15:56:41 -04:00

* Setup prettier and precommit hooks * Format code with prettier * Use husky because it works... * Move prettier config to .prettierrc file * Implement fixing markdown file formatting when running lint-fix script * Format markdown files * Add .json file formatting * Fixes json file formatting * Add pretteir linting step * Remove tslint * Use gitignore for prettier * Fix linting errors * Ignore submodule folder
35 lines
1.3 KiB
Markdown
35 lines
1.3 KiB
Markdown
---
|
|
title: Micro
|
|
description: Setting up Apollo Server with Micro
|
|
---
|
|
|
|
[](https://badge.fury.io/js/apollo-server-core) [](https://travis-ci.org/apollographql/apollo-server) [](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/)
|
|
|
|
```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);
|
|
```
|