10
10
import { describe , it } from 'mocha' ;
11
11
import { expect } from 'chai' ;
12
12
import dedent from '../../jsutils/dedent' ;
13
- import invariant from '../../jsutils/invariant' ;
14
13
import { printSchema , printIntrospectionSchema } from '../schemaPrinter' ;
15
14
import { buildSchema } from '../buildASTSchema' ;
16
15
import {
@@ -127,21 +126,12 @@ describe('Type System Printer', () => {
127
126
fields : { str : { type : GraphQLString } } ,
128
127
} ) ;
129
128
130
- const Query = new GraphQLObjectType ( {
131
- name : 'Query' ,
132
- fields : { foo : { type : FooType } } ,
133
- } ) ;
134
-
135
- const Schema = new GraphQLSchema ( { query : Query } ) ;
129
+ const Schema = new GraphQLSchema ( { types : [ FooType ] } ) ;
136
130
const output = printForTest ( Schema ) ;
137
131
expect ( output ) . to . equal ( dedent `
138
132
type Foo {
139
133
str: String
140
134
}
141
-
142
- type Query {
143
- foo: Foo
144
- }
145
135
` ) ;
146
136
} ) ;
147
137
@@ -304,15 +294,7 @@ describe('Type System Printer', () => {
304
294
interfaces : [ FooType ] ,
305
295
} ) ;
306
296
307
- const Query = new GraphQLObjectType ( {
308
- name : 'Query' ,
309
- fields : { bar : { type : BarType } } ,
310
- } ) ;
311
-
312
- const Schema = new GraphQLSchema ( {
313
- query : Query ,
314
- types : [ BarType ] ,
315
- } ) ;
297
+ const Schema = new GraphQLSchema ( { types : [ BarType ] } ) ;
316
298
const output = printForTest ( Schema ) ;
317
299
expect ( output ) . to . equal ( dedent `
318
300
type Bar implements Foo {
@@ -322,10 +304,6 @@ describe('Type System Printer', () => {
322
304
interface Foo {
323
305
str: String
324
306
}
325
-
326
- type Query {
327
- bar: Bar
328
- }
329
307
` ) ;
330
308
} ) ;
331
309
@@ -349,15 +327,7 @@ describe('Type System Printer', () => {
349
327
interfaces : [ FooType , BaazType ] ,
350
328
} ) ;
351
329
352
- const Query = new GraphQLObjectType ( {
353
- name : 'Query' ,
354
- fields : { bar : { type : BarType } } ,
355
- } ) ;
356
-
357
- const Schema = new GraphQLSchema ( {
358
- query : Query ,
359
- types : [ BarType ] ,
360
- } ) ;
330
+ const Schema = new GraphQLSchema ( { types : [ BarType ] } ) ;
361
331
const output = printForTest ( Schema ) ;
362
332
expect ( output ) . to . equal ( dedent `
363
333
interface Baaz {
@@ -372,10 +342,6 @@ describe('Type System Printer', () => {
372
342
interface Foo {
373
343
str: String
374
344
}
375
-
376
- type Query {
377
- bar: Bar
378
- }
379
345
` ) ;
380
346
} ) ;
381
347
@@ -404,15 +370,7 @@ describe('Type System Printer', () => {
404
370
types : [ FooType , BarType ] ,
405
371
} ) ;
406
372
407
- const Query = new GraphQLObjectType ( {
408
- name : 'Query' ,
409
- fields : {
410
- single : { type : SingleUnion } ,
411
- multiple : { type : MultipleUnion } ,
412
- } ,
413
- } ) ;
414
-
415
- const Schema = new GraphQLSchema ( { query : Query } ) ;
373
+ const Schema = new GraphQLSchema ( { types : [ SingleUnion , MultipleUnion ] } ) ;
416
374
const output = printForTest ( Schema ) ;
417
375
expect ( output ) . to . equal ( dedent `
418
376
type Bar {
@@ -425,11 +383,6 @@ describe('Type System Printer', () => {
425
383
426
384
union MultipleUnion = Foo | Bar
427
385
428
- type Query {
429
- single: SingleUnion
430
- multiple: MultipleUnion
431
- }
432
-
433
386
union SingleUnion = Foo
434
387
` ) ;
435
388
} ) ;
@@ -442,80 +395,41 @@ describe('Type System Printer', () => {
442
395
} ,
443
396
} ) ;
444
397
445
- const Query = new GraphQLObjectType ( {
446
- name : 'Query' ,
447
- fields : {
448
- str : {
449
- type : GraphQLString ,
450
- args : { argOne : { type : InputType } } ,
451
- } ,
452
- } ,
453
- } ) ;
454
-
455
- const Schema = new GraphQLSchema ( { query : Query } ) ;
398
+ const Schema = new GraphQLSchema ( { types : [ InputType ] } ) ;
456
399
const output = printForTest ( Schema ) ;
457
400
expect ( output ) . to . equal ( dedent `
458
401
input InputType {
459
402
int: Int
460
403
}
461
-
462
- type Query {
463
- str(argOne: InputType): String
464
- }
465
404
` ) ;
466
405
} ) ;
467
406
468
407
it ( 'Custom Scalar' , ( ) => {
469
408
const OddType = new GraphQLScalarType ( {
470
409
name : 'Odd' ,
471
- serialize ( value ) {
472
- invariant ( typeof value === 'number' ) ;
473
- return value % 2 === 1 ? value : null ;
474
- } ,
475
- } ) ;
476
-
477
- const Query = new GraphQLObjectType ( {
478
- name : 'Query' ,
479
- fields : {
480
- odd : { type : OddType } ,
481
- } ,
410
+ serialize ( ) { } ,
482
411
} ) ;
483
412
484
- const Schema = new GraphQLSchema ( { query : Query } ) ;
413
+ const Schema = new GraphQLSchema ( { types : [ OddType ] } ) ;
485
414
const output = printForTest ( Schema ) ;
486
415
expect ( output ) . to . equal ( dedent `
487
416
scalar Odd
488
-
489
- type Query {
490
- odd: Odd
491
- }
492
417
` ) ;
493
418
} ) ;
494
419
495
420
it ( 'Enum' , ( ) => {
496
421
const RGBType = new GraphQLEnumType ( {
497
422
name : 'RGB' ,
498
423
values : {
499
- RED : { value : 0 } ,
500
- GREEN : { value : 1 } ,
501
- BLUE : { value : 2 } ,
502
- } ,
503
- } ) ;
504
-
505
- const Query = new GraphQLObjectType ( {
506
- name : 'Query' ,
507
- fields : {
508
- rgb : { type : RGBType } ,
424
+ RED : { } ,
425
+ GREEN : { } ,
426
+ BLUE : { } ,
509
427
} ,
510
428
} ) ;
511
429
512
- const Schema = new GraphQLSchema ( { query : Query } ) ;
430
+ const Schema = new GraphQLSchema ( { types : [ RGBType ] } ) ;
513
431
const output = printForTest ( Schema ) ;
514
432
expect ( output ) . to . equal ( dedent `
515
- type Query {
516
- rgb: RGB
517
- }
518
-
519
433
enum RGB {
520
434
RED
521
435
GREEN
@@ -525,29 +439,15 @@ describe('Type System Printer', () => {
525
439
} ) ;
526
440
527
441
it ( 'Prints custom directives' , ( ) => {
528
- const Query = new GraphQLObjectType ( {
529
- name : 'Query' ,
530
- fields : {
531
- field : { type : GraphQLString } ,
532
- } ,
533
- } ) ;
534
-
535
442
const CustomDirective = new GraphQLDirective ( {
536
443
name : 'customDirective' ,
537
444
locations : [ DirectiveLocation . FIELD ] ,
538
445
} ) ;
539
446
540
- const Schema = new GraphQLSchema ( {
541
- query : Query ,
542
- directives : [ CustomDirective ] ,
543
- } ) ;
447
+ const Schema = new GraphQLSchema ( { directives : [ CustomDirective ] } ) ;
544
448
const output = printForTest ( Schema ) ;
545
449
expect ( output ) . to . equal ( dedent `
546
450
directive @customDirective on FIELD
547
-
548
- type Query {
549
- field: String
550
- }
551
451
` ) ;
552
452
} ) ;
553
453
@@ -609,13 +509,7 @@ describe('Type System Printer', () => {
609
509
} ) ;
610
510
611
511
it ( 'Print Introspection Schema' , ( ) => {
612
- const Query = new GraphQLObjectType ( {
613
- name : 'Query' ,
614
- fields : {
615
- onlyField : { type : GraphQLString } ,
616
- } ,
617
- } ) ;
618
- const Schema = new GraphQLSchema ( { query : Query } ) ;
512
+ const Schema = new GraphQLSchema ( { } ) ;
619
513
const output = printIntrospectionSchema ( Schema ) ;
620
514
const introspectionSchema = dedent `
621
515
"""
@@ -848,13 +742,7 @@ describe('Type System Printer', () => {
848
742
} ) ;
849
743
850
744
it ( 'Print Introspection Schema with comment descriptions' , ( ) => {
851
- const Query = new GraphQLObjectType ( {
852
- name : 'Query' ,
853
- fields : {
854
- onlyField : { type : GraphQLString } ,
855
- } ,
856
- } ) ;
857
- const Schema = new GraphQLSchema ( { query : Query } ) ;
745
+ const Schema = new GraphQLSchema ( { } ) ;
858
746
const output = printIntrospectionSchema ( Schema , {
859
747
commentDescriptions : true ,
860
748
} ) ;
0 commit comments