-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloGraphql.js
More file actions
44 lines (37 loc) · 1.06 KB
/
HelloGraphql.js
File metadata and controls
44 lines (37 loc) · 1.06 KB
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
34
35
36
37
38
39
40
41
42
43
44
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const graphqlHTTP = require('express-graphql');
const graphqlSchema = require('./graphqlSchema');
const {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString
} = require('graphql');
let app = express();
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
hello: {
type: GraphQLString,
resolve() {
return 'Hello from graphql';
}
}
}
})
});
// Configure morgan to log your requests, with a standard date & time format
morgan.token('time', (req, res) => new Date().toISOString());
app.use(morgan('[:time] :remote-addr :method :url :status :res[content-length] :response-time ms'));
// Setup bodyParsing middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Mount it at root, as this will be the only end point needed
app.use('/', graphqlHTTP({
schema: graphqlSchema,
graphiql: true
}));
app.listen(3000);