-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathhello-clean.js
40 lines (35 loc) · 1.16 KB
/
hello-clean.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
/* eslint-disable import/no-unresolved, node/no-missing-import, eslint-comments/disable-enable-pair */
import bodyParser from '@nanoexpress/middleware-body-parser';
import graphql from '@nanoexpress/middleware-graphql';
import graphqlExports from 'graphql';
// eslint-disable-next-line import/extensions
import { makeBehavior } from 'graphql-ws/lib/use/uWebSockets';
import nanoexpress from 'nanoexpress';
const app = nanoexpress();
app.use(bodyParser());
// Construct a schema, using GraphQL schema language
const schema = graphqlExports.buildSchema(`
type Query {
hello: String
}
type Subscription {
greetings: String
}
`);
// The roots provide resolvers for each GraphQL operation
const rootQueryMutation = {
hello: () => 'Hello World!'
};
const rootsSubscription = {
subscription: {
greetings: async function* sayHiIn5Languages() {
// eslint-disable-next-line no-restricted-syntax
for (const hi of ['Hi', 'Bonjour', 'Hola', 'Ciao', 'Zdravo']) {
yield { greetings: hi };
}
}
}
};
app.post('/graphql', graphql(schema, rootQueryMutation));
app.ws('/graphql', makeBehavior({ schema, roots: rootsSubscription }));
app.listen(4000);