forked from clintonwoo/hackernews-react-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphiql.js
57 lines (48 loc) · 1.13 KB
/
graphiql.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* WARNING: THIS USES THE REAL SCHEMA AND DATABASE!
*
* Take care not to cause data loss but the app should be secure
*/
// TODO: Can make this graphql server part of the main server using feature flag
// Example GraphiQL server https://github.com/graphql/graphiql/tree/master/example
import express from 'express';
import bodyParser from 'body-parser';
import {
graphqlExpress,
graphiqlExpress,
} from 'apollo-server-express';
import Schema from './Schema';
import {
APP_PORT,
graphQLPath,
graphiQLPath,
GRAPHQL_URL,
GRAPHIQL_URL,
} from '../config';
import {
Comment,
Feed,
NewsItem,
User,
} from './Models';
const logger = console;
const app = express();
// Mount GraphQL Server middleware
app.use(graphQLPath, bodyParser.json(), graphqlExpress(request => ({
schema: Schema,
rootValue: { request },
context: {
Comment,
Feed,
NewsItem,
User,
},
debug: true,
})));
app.use(graphiQLPath, graphiqlExpress({
endpointURL: graphQLPath,
}));
app.listen(APP_PORT, () => {
logger.info(`==> 📈 GraphQL Server on ${GRAPHQL_URL}`);
logger.info(`==> 🌎 Go to ${GRAPHIQL_URL}`);
});