-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (29 loc) · 891 Bytes
/
server.js
File metadata and controls
38 lines (29 loc) · 891 Bytes
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
import express from 'express';
import { graphqlExpress, graphiqlExpress } from 'graphql-server-express';
import { makeExecutableSchema } from 'graphql-tools';
import bodyParser from 'body-parser';
import schema from './data/schema';
import resolvers from './data/resolvers';
const graphQLServer = express();
const executableSchema = makeExecutableSchema({
typeDefs: [schema],
resolvers,
});
graphQLServer.use('/graphql', bodyParser.json(), graphqlExpress((req) => {
let ip = req.ip;
const inDevelopment = ip === '::1';
if (inDevelopment) {
ip = '8.8.8.8';
}
return {
schema: executableSchema,
context: { ip },
};
}));
graphQLServer.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}));
const GRAPHQL_PORT = 8080;
graphQLServer.listen(GRAPHQL_PORT, () => console.log(
`GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}`
));