|
1 | | -import { GraphQLServer, PubSub } from 'graphql-yoga'; |
2 | | -import { formatError } from 'apollo-errors'; |
3 | | -import * as jwt from 'express-jwt'; |
4 | | -import * as faker from 'faker/locale/en'; |
5 | | -import * as compression from 'compression'; |
| 1 | +import { GraphQLServer, PubSub } from 'graphql-yoga' |
| 2 | +import { formatError } from 'apollo-errors' |
| 3 | +import * as jwt from 'express-jwt' |
| 4 | +import * as faker from 'faker/locale/en' |
| 5 | +import * as compression from 'compression' |
6 | 6 |
|
7 | | -import resolvers from './resolvers'; |
| 7 | +import resolvers from './resolvers' |
8 | 8 | import defaultPlaygroundQuery from './initQuery' |
9 | 9 |
|
10 | | -const { JWT_SECRET } = process.env; |
| 10 | +const { JWT_SECRET } = process.env |
11 | 11 |
|
12 | | -const pubsub = new PubSub(); |
| 12 | +const pubsub = new PubSub() |
13 | 13 | const server = new GraphQLServer({ |
14 | 14 | typeDefs: './src/schema.graphql', |
15 | 15 | resolvers, |
16 | | - context: req => ({ |
| 16 | + context: (req) => ({ |
17 | 17 | ...req, |
18 | 18 | jwtSecret: JWT_SECRET, |
19 | 19 | faker, |
20 | | - pubsub |
21 | | - }) |
22 | | -}); |
| 20 | + pubsub, |
| 21 | + }), |
| 22 | +}) |
23 | 23 |
|
24 | | -server.express.disable('x-powered-by'); |
| 24 | +server.express.disable('x-powered-by') |
25 | 25 |
|
26 | 26 | server.express.use( |
27 | 27 | '/graphql', |
28 | 28 | jwt({ |
29 | 29 | secret: JWT_SECRET, |
30 | | - credentialsRequired: false |
31 | | - }) |
32 | | -); |
| 30 | + credentialsRequired: false, |
| 31 | + }), |
| 32 | +) |
33 | 33 |
|
34 | | -server.express.use(compression()); |
| 34 | +server.express.use(compression()) |
35 | 35 |
|
36 | 36 | const options = { |
37 | 37 | formatError, |
38 | 38 | endpoint: '/graphql', |
39 | 39 | subscriptions: '/subscriptions', |
40 | 40 | playground: '/', |
41 | | - defaultPlaygroundQuery |
42 | | -}; |
| 41 | + defaultPlaygroundQuery, |
| 42 | +} |
43 | 43 |
|
44 | 44 | server.start(options, ({ port }) => |
45 | | - console.log(`Server is running on PORT: ${port}`) |
46 | | -); |
| 45 | + console.log(`Server is running on PORT: ${port}`), |
| 46 | +) |
0 commit comments