-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (31 loc) · 915 Bytes
/
server.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
import 'dotenv/config'
import { createServer } from "node:http";
import { createYoga } from "graphql-yoga";
import { useDeferStream } from '@graphql-yoga/plugin-defer-stream'
import { useJWT } from '@graphql-yoga/plugin-jwt'
import { schema } from "./schema.js";
const signingKey = process.env.JWT_SECRET;
// Create a Yoga instance with a GraphQL schema.
const yoga = createYoga({
schema,
cors: {
origin: 'http://localhost:4000',
credentials: true,
allowedHeaders: ['X-Custom-Header'],
methods: ['POST']
},
plugins: [
useDeferStream(),
useJWT({
issuer: 'http://demo.stellate.co',
signingKey,
algorithms: ['HS256'],
})
]
});
// Pass it into a server to hook into request handlers.
const server = createServer(yoga);
// Start the server and you're done!
server.listen(4000, () => {
console.info("Server is running on http://localhost:4000/graphql");
});