apollo-server/integrations.md

34 lines
744 B
Markdown
Raw Normal View History

2016-06-14 12:07:56 -07:00
# expressApollo
An Express Middleware for the Apollo Server
## Example Usage
```js
import * as graphql from "graphql";
2016-06-14 12:07:56 -07:00
import * as express from "express";
import * as bodyParser from "body-parser";
import { graphqlHTTP, renderGraphiQL } from "apollo-server";
2016-06-14 12:07:56 -07:00
const port = 3000;
2016-09-27 16:53:04 -07:00
const endpointURL = "/graphql";
2016-06-14 12:07:56 -07:00
const app = express();
2016-06-14 12:07:56 -07:00
const schema = new graphql.GraphQLSchema({
query: new graphql.GraphQLObjectType({
name: "Query",
2016-06-14 12:07:56 -07:00
fields: {
testString: { type: graphql.GraphQLString }
}
})
});
app.use(bodyParser.json());
app.get("/", renderGraphiQL({endpointURL}));
app.post(endpointURL, graphqlHTTP({schema}));
2016-06-14 12:07:56 -07:00
app.listen(port, () => {
console.log(`Server is listen on ${port}`);
});
```