apollo-server/packages/graphql-server-micro/README.md
Jim Cummins c2333798ed fix(graphql-server-micro): micro-router requires one 200 route
Fixes #449 for now by adding a noop route to the example so that graphiql does not 404.
2017-07-07 14:01:31 -05:00

32 lines
932 B
Markdown

# graphql-server-micro
This is the [Micro](https://github.com/zeit/micro) integration for the Apollo community GraphQL Server. [Read the docs.](http://dev.apollodata.com/tools/apollo-server/index.html)
## Example
```typescript
import { microGraphiql, microGraphql } from "graphql-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),
get("/noop", (req, res) => {
// Micro router requires at least one 200 route
// or you will always get a 404
return send(res, 200, "");
}),
(req, res) => send(res, 404, "not found"),
),
);
server.listen(3000);
```