-
Notifications
You must be signed in to change notification settings - Fork 17
/
example.js
33 lines (29 loc) · 840 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const express = require('express');
const { buildSchema } = require('graphql');
const graphqlHTTP = require('express-graphql');
let port = 3000;
/* Here a simple schema is constructed using the GraphQL schema language.
More information can be found in the GraphQL spec release */
let schema = buildSchema(`
type Query {
postTitle: String,
blogTitle: String
}
`);
// Root provides a resolver function for each API endpoint
let root = {
postTitle: () => {
return 'Build a Simple GraphQL Server With Express and NodeJS';
},
blogTitle: () => {
return 'scotch.io';
}
};
const app = express();
app.use('/', graphqlHTTP({
schema: schema,
rootValue: root,
graphiql: true//Set to false if you don't want graphiql enabled
}));
app.listen(port);
console.log('GraphQL API server running at localhost:'+ port);