1const {
2 GraphQLList,
3 GraphQLObjectType,
4 GraphQLSchema,
5 GraphQLString,
6} = require('graphql');
7
8const Alphabet = new GraphQLObjectType({
9 name: 'Alphabet',
10 fields: {
11 char: {
12 type: GraphQLString,
13 },
14 },
15});
16
17const schema = new GraphQLSchema({
18 query: new GraphQLObjectType({
19 name: 'Query',
20 fields: () => ({
21 list: {
22 type: new GraphQLList(Alphabet),
23 resolve() {
24 return [{ char: 'Where are my letters?' }];
25 },
26 },
27 }),
28 }),
29 subscription: new GraphQLObjectType({
30 name: 'Subscription',
31 fields: () => ({
32 alphabet: {
33 type: Alphabet,
34 resolve(root) {
35 return root;
36 },
37 subscribe: async function* () {
38 for (let letter = 65; letter <= 90; letter++) {
39 await new Promise(resolve => setTimeout(resolve, 500));
40 yield { char: String.fromCharCode(letter) };
41 }
42 },
43 },
44 }),
45 }),
46});
47
48module.exports = { schema };