Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1const { 2 GraphQLList, 3 GraphQLObjectType, 4 GraphQLSchema, 5 GraphQLString, 6} = require('graphql'); 7 8const schema = new GraphQLSchema({ 9 query: new GraphQLObjectType({ 10 name: 'Query', 11 fields: () => ({ 12 alphabet: { 13 type: new GraphQLList( 14 new GraphQLObjectType({ 15 name: 'Alphabet', 16 fields: { 17 char: { 18 type: GraphQLString, 19 }, 20 }, 21 }) 22 ), 23 resolve: async function* () { 24 for (let letter = 65; letter <= 90; letter++) { 25 await new Promise(resolve => setTimeout(resolve, 500)); 26 yield { char: String.fromCharCode(letter) }; 27 } 28 }, 29 }, 30 song: { 31 type: new GraphQLObjectType({ 32 name: 'Song', 33 fields: () => ({ 34 firstVerse: { 35 type: GraphQLString, 36 resolve: () => "Now I know my ABC's.", 37 }, 38 secondVerse: { 39 type: GraphQLString, 40 resolve: () => 41 new Promise(resolve => 42 setTimeout( 43 () => resolve("Next time won't you sing with me?"), 44 5000 45 ) 46 ), 47 }, 48 }), 49 }), 50 resolve: () => 51 new Promise(resolve => setTimeout(() => resolve('goodbye'), 1000)), 52 }, 53 }), 54 }), 55}); 56 57module.exports = { schema };