5
5
* This source code is licensed under the MIT license found in the
6
6
* LICENSE file in the root directory of this source tree.
7
7
*/
8
+
9
+ const graphql = require ( 'graphql' ) ;
10
+
8
11
const {
9
12
GraphQLSchema,
10
13
GraphQLObjectType,
@@ -22,7 +25,12 @@ const {
22
25
GraphQLStreamDirective,
23
26
specifiedDirectives,
24
27
version,
25
- } = require ( 'graphql' ) ;
28
+ } = graphql ;
29
+
30
+ const directives =
31
+ parseInt ( version , 10 ) > 16
32
+ ? [ ...specifiedDirectives , GraphQLDeferDirective , GraphQLStreamDirective ]
33
+ : specifiedDirectives ;
26
34
27
35
// Test Schema
28
36
const TestEnum = new GraphQLEnumType ( {
@@ -374,7 +382,7 @@ const TestSubscriptionType = new GraphQLObjectType({
374
382
} ,
375
383
async * subscribe ( root , args ) {
376
384
for ( const hi of [ 'Hi' , 'Bonjour' , 'Hola' , 'Ciao' , 'Zdravo' ] ) {
377
- if ( args . delay ) {
385
+ if ( args ? .delay ) {
378
386
await sleep ( args . delay ) ;
379
387
}
380
388
yield { message : hi } ;
@@ -384,20 +392,12 @@ const TestSubscriptionType = new GraphQLObjectType({
384
392
} ,
385
393
} ) ;
386
394
387
- const schemaConfig = {
395
+ const myTestSchema = new GraphQLSchema ( {
388
396
query : TestType ,
389
397
mutation : TestMutationType ,
390
398
subscription : TestSubscriptionType ,
391
399
description : 'This is a test schema for GraphiQL' ,
392
- } ;
393
-
394
- exports . schema = new GraphQLSchema ( {
395
- ...schemaConfig ,
396
- directives :
397
- parseInt ( version , 10 ) > 16
398
- ? [ ...specifiedDirectives , GraphQLDeferDirective , GraphQLStreamDirective ]
399
- : specifiedDirectives ,
400
+ directives,
400
401
} ) ;
401
402
402
- // Same schema but without defer/stream directives
403
- exports . sseSchema = new GraphQLSchema ( schemaConfig ) ;
403
+ exports . schema = myTestSchema ;
0 commit comments