2016-06-14 12:07:56 -07:00
|
|
|
# expressApollo
|
|
|
|
|
|
|
|
An Express Middleware for the Apollo Server
|
|
|
|
|
|
|
|
## Example Usage
|
|
|
|
|
|
|
|
```js
|
2016-06-30 08:53:51 -07:00
|
|
|
import * as graphql from "graphql";
|
2016-06-14 12:07:56 -07:00
|
|
|
import * as express from "express";
|
|
|
|
import * as bodyParser from "body-parser";
|
2016-10-18 09:36:07 +03:00
|
|
|
import { apolloExpress, graphiqlExpress } from "graphql-server-express";
|
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-30 08:53:51 -07:00
|
|
|
|
2016-06-14 12:07:56 -07:00
|
|
|
const schema = new graphql.GraphQLSchema({
|
|
|
|
query: new graphql.GraphQLObjectType({
|
2016-06-30 08:53:51 -07:00
|
|
|
name: "Query",
|
2016-06-14 12:07:56 -07:00
|
|
|
fields: {
|
|
|
|
testString: { type: graphql.GraphQLString }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2016-06-30 08:53:51 -07:00
|
|
|
app.use(bodyParser.json());
|
2016-10-18 09:36:07 +03:00
|
|
|
app.get("/", graphiqlExpress({endpointURL}));
|
|
|
|
app.post(endpointURL, apolloExpress({schema}));
|
2016-06-14 12:07:56 -07:00
|
|
|
|
|
|
|
app.listen(port, () => {
|
|
|
|
console.log(`Server is listen on ${port}`);
|
|
|
|
});
|
|
|
|
```
|