forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 5
/
buildClientSchema-test.js
869 lines (719 loc) · 24.1 KB
/
buildClientSchema-test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
// @flow strict
import { describe, it } from 'mocha';
import { expect } from 'chai';
import dedent from '../../jsutils/dedent';
import { buildClientSchema } from '../buildClientSchema';
import { introspectionFromSchema } from '../introspectionFromSchema';
import {
buildSchema,
printSchema,
graphqlSync,
assertEnumType,
GraphQLSchema,
GraphQLObjectType,
GraphQLEnumType,
GraphQLInt,
GraphQLFloat,
GraphQLString,
GraphQLBoolean,
GraphQLID,
} from '../../';
/**
* This function does a full cycle of going from a string with the contents of
* the SDL, build in-memory GraphQLSchema from it, produce a client-side
* representation of the schema by using "buildClientSchema"and then finally
* printing that that schema into the SDL
*/
function cycleIntrospection(sdlString) {
const serverSchema = buildSchema(sdlString);
const initialIntrospection = introspectionFromSchema(serverSchema);
const clientSchema = buildClientSchema(initialIntrospection);
const secondIntrospection = introspectionFromSchema(clientSchema);
/**
* If the client then runs the introspection query against the client-side
* schema, it should get a result identical to what was returned by the server
*/
expect(secondIntrospection).to.deep.equal(initialIntrospection);
return printSchema(clientSchema);
}
describe('Type System: build schema from introspection', () => {
it('builds a simple schema', () => {
const sdl = dedent`
schema {
query: Simple
}
"""This is simple type"""
type Simple {
"""This is a string field"""
string: String
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema without the query type', () => {
const sdl = dedent`
type Query {
foo: String
}
`;
const schema = buildSchema(sdl);
const introspection = introspectionFromSchema(schema);
delete introspection.__schema.queryType;
const clientSchema = buildClientSchema(introspection);
expect(clientSchema.getQueryType()).to.equal(null);
expect(printSchema(clientSchema)).to.equal(sdl);
});
it('builds a simple schema with all operation types', () => {
const sdl = dedent`
schema {
query: QueryType
mutation: MutationType
subscription: SubscriptionType
}
"""This is a simple mutation type"""
type MutationType {
"""Set the string field"""
string: String
}
"""This is a simple query type"""
type QueryType {
"""This is a string field"""
string: String
}
"""This is a simple subscription type"""
type SubscriptionType {
"""This is a string field"""
string: String
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('uses built-in scalars when possible', () => {
const sdl = dedent`
scalar CustomScalar
type Query {
int: Int
float: Float
string: String
boolean: Boolean
id: ID
custom: CustomScalar
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
const schema = buildSchema(sdl);
const introspection = introspectionFromSchema(schema);
const clientSchema = buildClientSchema(introspection);
// Built-ins are used
expect(clientSchema.getType('Int')).to.equal(GraphQLInt);
expect(clientSchema.getType('Float')).to.equal(GraphQLFloat);
expect(clientSchema.getType('String')).to.equal(GraphQLString);
expect(clientSchema.getType('Boolean')).to.equal(GraphQLBoolean);
expect(clientSchema.getType('ID')).to.equal(GraphQLID);
// Custom are built
const customScalar = schema.getType('CustomScalar');
expect(clientSchema.getType('CustomScalar')).not.to.equal(customScalar);
});
it('include standard type only if it is used', () => {
const schema = buildSchema(`
type Query {
foo: String
}
`);
const introspection = introspectionFromSchema(schema);
const clientSchema = buildClientSchema(introspection);
expect(clientSchema.getType('Int')).to.equal(undefined);
expect(clientSchema.getType('Float')).to.equal(undefined);
expect(clientSchema.getType('ID')).to.equal(undefined);
});
it('builds a schema with a recursive type reference', () => {
const sdl = dedent`
schema {
query: Recur
}
type Recur {
recur: Recur
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema with a circular type reference', () => {
const sdl = dedent`
type Dog {
bestFriend: Human
}
type Human {
bestFriend: Dog
}
type Query {
dog: Dog
human: Human
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema with an interface', () => {
const sdl = dedent`
type Dog implements Friendly {
bestFriend: Friendly
}
interface Friendly {
"""The best friend of this friendly thing"""
bestFriend: Friendly
}
type Human implements Friendly {
bestFriend: Friendly
}
type Query {
friendly: Friendly
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema with an implicit interface', () => {
const sdl = dedent`
type Dog implements Friendly {
bestFriend: Friendly
}
interface Friendly {
"""The best friend of this friendly thing"""
bestFriend: Friendly
}
type Query {
dog: Dog
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema with a union', () => {
const sdl = dedent`
type Dog {
bestFriend: Friendly
}
union Friendly = Dog | Human
type Human {
bestFriend: Friendly
}
type Query {
friendly: Friendly
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema with complex field values', () => {
const sdl = dedent`
type Query {
string: String
listOfString: [String]
nonNullString: String!
nonNullListOfString: [String]!
nonNullListOfNonNullString: [String!]!
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema with field arguments', () => {
const sdl = dedent`
type Query {
"""A field with a single arg"""
one(
"""This is an int arg"""
intArg: Int
): String
"""A field with a two args"""
two(
"""This is an list of int arg"""
listArg: [Int]
"""This is a required arg"""
requiredArg: Boolean!
): String
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema with default value on custom scalar field', () => {
const sdl = dedent`
scalar CustomScalar
type Query {
testField(testArg: CustomScalar = "default"): String
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema with an enum', () => {
const foodEnum = new GraphQLEnumType({
name: 'Food',
description: 'Varieties of food stuffs',
values: {
VEGETABLES: {
description: 'Foods that are vegetables.',
value: 1,
},
FRUITS: {
description: 'Foods that are fruits.',
value: 2,
},
OILS: {
description: 'Foods that are oils.',
value: 3,
},
DAIRY: {
description: 'Foods that are dairy.',
value: 4,
},
MEAT: {
description: 'Foods that are meat.',
value: 5,
},
},
});
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'EnumFields',
fields: {
food: {
description: 'Repeats the arg you give it',
type: foodEnum,
args: {
kind: {
description: 'what kind of food?',
type: foodEnum,
},
},
},
},
}),
});
const introspection = introspectionFromSchema(schema);
const clientSchema = buildClientSchema(introspection);
const secondIntrospection = introspectionFromSchema(clientSchema);
expect(secondIntrospection).to.deep.equal(introspection);
// It's also an Enum type on the client.
const clientFoodEnum = assertEnumType(clientSchema.getType('Food'));
// Client types do not get server-only values, so `value` mirrors `name`,
// rather than using the integers defined in the "server" schema.
expect(clientFoodEnum.getValues()).to.deep.equal([
{
name: 'VEGETABLES',
value: 'VEGETABLES',
description: 'Foods that are vegetables.',
isDeprecated: false,
deprecationReason: null,
astNode: undefined,
},
{
name: 'FRUITS',
value: 'FRUITS',
description: 'Foods that are fruits.',
isDeprecated: false,
deprecationReason: null,
astNode: undefined,
},
{
name: 'OILS',
value: 'OILS',
description: 'Foods that are oils.',
isDeprecated: false,
deprecationReason: null,
astNode: undefined,
},
{
name: 'DAIRY',
value: 'DAIRY',
description: 'Foods that are dairy.',
isDeprecated: false,
deprecationReason: null,
astNode: undefined,
},
{
name: 'MEAT',
value: 'MEAT',
description: 'Foods that are meat.',
isDeprecated: false,
deprecationReason: null,
astNode: undefined,
},
]);
});
it('builds a schema with an input object', () => {
const sdl = dedent`
"""An input address"""
input Address {
"""What street is this address?"""
street: String!
"""The city the address is within?"""
city: String!
"""The country (blank will assume USA)."""
country: String = "USA"
}
type Query {
"""Get a geocode from an address"""
geocode(
"""The address to lookup"""
address: Address
): String
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema with field arguments with default values', () => {
const sdl = dedent`
input Geo {
lat: Float
lon: Float
}
type Query {
defaultInt(intArg: Int = 30): String
defaultList(listArg: [Int] = [1, 2, 3]): String
defaultObject(objArg: Geo = {lat: 37.485, lon: -122.148}): String
defaultNull(intArg: Int = null): String
noDefault(intArg: Int): String
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema with custom directives', () => {
const sdl = dedent`
"""This is a custom directive"""
directive @customDirective on FIELD
type Query {
string: String
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('builds a schema without directives', () => {
const sdl = dedent`
type Query {
string: String
}
`;
const schema = buildSchema(sdl);
const introspection = introspectionFromSchema(schema);
delete introspection.__schema.directives;
const clientSchema = buildClientSchema(introspection);
expect(schema.getDirectives()).to.have.lengthOf.above(0);
expect(clientSchema.getDirectives()).to.deep.equal([]);
expect(printSchema(clientSchema)).to.equal(sdl);
});
it('builds a schema with legacy names', () => {
const sdl = dedent`
type Query {
__badName: String
}
`;
const allowedLegacyNames = ['__badName'];
const schema = buildSchema(sdl, { allowedLegacyNames });
const introspection = introspectionFromSchema(schema);
const clientSchema = buildClientSchema(introspection, {
allowedLegacyNames,
});
expect(schema.__allowedLegacyNames).to.deep.equal(['__badName']);
expect(printSchema(clientSchema)).to.equal(sdl);
});
it('builds a schema aware of deprecation', () => {
const sdl = dedent`
enum Color {
"""So rosy"""
RED
"""So grassy"""
GREEN
"""So calming"""
BLUE
"""So sickening"""
MAUVE @deprecated(reason: "No longer in fashion")
}
type Query {
"""This is a shiny string field"""
shinyString: String
"""This is a deprecated string field"""
deprecatedString: String @deprecated(reason: "Use shinyString")
color: Color
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
it('can use client schema for limited execution', () => {
const schema = buildSchema(`
scalar CustomScalar
type Query {
foo(custom1: CustomScalar, custom2: CustomScalar): String
}
`);
const introspection = introspectionFromSchema(schema);
const clientSchema = buildClientSchema(introspection);
const result = graphqlSync({
schema: clientSchema,
source:
'query Limited($v: CustomScalar) { foo(custom1: 123, custom2: $v) }',
rootValue: { foo: 'bar', unused: 'value' },
variableValues: { v: 'baz' },
});
expect(result.data).to.deep.equal({ foo: 'bar' });
});
describe('throws when given invalid introspection', () => {
const dummySchema = buildSchema(`
type Query {
foo(bar: String): String
}
union SomeUnion = Query
enum SomeEnum { FOO }
input SomeInputObject {
foo: String
}
directive @SomeDirective on QUERY
`);
it('throws when introspection is missing __schema property', () => {
// $DisableFlowOnNegativeTest
expect(() => buildClientSchema(null)).to.throw(
'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: null',
);
// $DisableFlowOnNegativeTest
expect(() => buildClientSchema({})).to.throw(
'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: {}',
);
});
it('throws when referenced unknown type', () => {
const introspection = introspectionFromSchema(dummySchema);
// $DisableFlowOnNegativeTest
introspection.__schema.types = introspection.__schema.types.filter(
({ name }) => name !== 'Query',
);
expect(() => buildClientSchema(introspection)).to.throw(
'Invalid or incomplete schema, unknown type: Query. Ensure that a full introspection query is used in order to build a client schema.',
);
});
it('throws when missing definition for one of the standard scalars', () => {
const schema = buildSchema(`
type Query {
foo: Float
}
`);
const introspection = introspectionFromSchema(schema);
// $DisableFlowOnNegativeTest
introspection.__schema.types = introspection.__schema.types.filter(
({ name }) => name !== 'Float',
);
expect(() => buildClientSchema(introspection)).to.throw(
'Invalid or incomplete schema, unknown type: Float. Ensure that a full introspection query is used in order to build a client schema.',
);
});
it('throws when type reference is missing name', () => {
const introspection = introspectionFromSchema(dummySchema);
expect(introspection).to.have.nested.property('__schema.queryType.name');
delete introspection.__schema.queryType.name;
expect(() => buildClientSchema(introspection)).to.throw(
'Unknown type reference: {}',
);
});
it('throws when missing kind', () => {
const introspection = introspectionFromSchema(dummySchema);
const queryTypeIntrospection = introspection.__schema.types.find(
({ name }) => name === 'Query',
);
expect(queryTypeIntrospection).to.have.property('kind');
// $DisableFlowOnNegativeTest
delete queryTypeIntrospection.kind;
expect(() => buildClientSchema(introspection)).to.throw(
'Invalid or incomplete introspection result. Ensure that a full introspection query is used in order to build a client schema',
);
});
it('throws when missing interfaces', () => {
const introspection = introspectionFromSchema(dummySchema);
const queryTypeIntrospection = introspection.__schema.types.find(
({ name }) => name === 'Query',
);
expect(queryTypeIntrospection).to.have.property('interfaces');
// $DisableFlowOnNegativeTest
delete queryTypeIntrospection.interfaces;
expect(() => buildClientSchema(introspection)).to.throw(
'Introspection result missing interfaces: { kind: "OBJECT", name: "Query",',
);
});
it('throws when missing fields', () => {
const introspection = introspectionFromSchema(dummySchema);
const queryTypeIntrospection = introspection.__schema.types.find(
({ name }) => name === 'Query',
);
expect(queryTypeIntrospection).to.have.property('fields');
// $DisableFlowOnNegativeTest
delete queryTypeIntrospection.fields;
expect(() => buildClientSchema(introspection)).to.throw(
'Introspection result missing fields: { kind: "OBJECT", name: "Query",',
);
});
it('throws when missing field args', () => {
const introspection = introspectionFromSchema(dummySchema);
const queryTypeIntrospection = introspection.__schema.types.find(
({ name }) => name === 'Query',
);
expect(queryTypeIntrospection).to.have.nested.property('fields[0].args');
// $DisableFlowOnNegativeTest
delete queryTypeIntrospection.fields[0].args;
expect(() => buildClientSchema(introspection)).to.throw(
'Introspection result missing field args: { name: "foo",',
);
});
it('throws when output type is used as an arg type', () => {
const introspection = introspectionFromSchema(dummySchema);
const queryTypeIntrospection = introspection.__schema.types.find(
({ name }) => name === 'Query',
);
expect(queryTypeIntrospection).to.have.nested.property(
'fields[0].args[0].type.name',
'String',
);
// $DisableFlowOnNegativeTest
queryTypeIntrospection.fields[0].args[0].type.name = 'SomeUnion';
expect(() => buildClientSchema(introspection)).to.throw(
'Introspection must provide input type for arguments, but received: SomeUnion.',
);
});
it('throws when input type is used as a field type', () => {
const introspection = introspectionFromSchema(dummySchema);
const queryTypeIntrospection = introspection.__schema.types.find(
({ name }) => name === 'Query',
);
expect(queryTypeIntrospection).to.have.nested.property(
'fields[0].type.name',
'String',
);
// $DisableFlowOnNegativeTest
queryTypeIntrospection.fields[0].type.name = 'SomeInputObject';
expect(() => buildClientSchema(introspection)).to.throw(
'Introspection must provide output type for fields, but received: SomeInputObject.',
);
});
it('throws when missing possibleTypes', () => {
const introspection = introspectionFromSchema(dummySchema);
const someUnionIntrospection = introspection.__schema.types.find(
({ name }) => name === 'SomeUnion',
);
expect(someUnionIntrospection).to.have.property('possibleTypes');
// $DisableFlowOnNegativeTest
delete someUnionIntrospection.possibleTypes;
expect(() => buildClientSchema(introspection)).to.throw(
'Introspection result missing possibleTypes: { kind: "UNION", name: "SomeUnion",',
);
});
it('throws when missing enumValues', () => {
const introspection = introspectionFromSchema(dummySchema);
const someEnumIntrospection = introspection.__schema.types.find(
({ name }) => name === 'SomeEnum',
);
expect(someEnumIntrospection).to.have.property('enumValues');
// $DisableFlowOnNegativeTest
delete someEnumIntrospection.enumValues;
expect(() => buildClientSchema(introspection)).to.throw(
'Introspection result missing enumValues: { kind: "ENUM", name: "SomeEnum",',
);
});
it('throws when missing inputFields', () => {
const introspection = introspectionFromSchema(dummySchema);
const someInputObjectIntrospection = introspection.__schema.types.find(
({ name }) => name === 'SomeInputObject',
);
expect(someInputObjectIntrospection).to.have.property('inputFields');
// $DisableFlowOnNegativeTest
delete someInputObjectIntrospection.inputFields;
expect(() => buildClientSchema(introspection)).to.throw(
'Introspection result missing inputFields: { kind: "INPUT_OBJECT", name: "SomeInputObject",',
);
});
it('throws when missing directive locations', () => {
const introspection = introspectionFromSchema(dummySchema);
const someDirectiveIntrospection = introspection.__schema.directives[0];
expect(someDirectiveIntrospection).to.deep.include({
name: 'SomeDirective',
locations: ['QUERY'],
});
delete someDirectiveIntrospection.locations;
expect(() => buildClientSchema(introspection)).to.throw(
'Introspection result missing directive locations: { name: "SomeDirective",',
);
});
it('throws when missing directive args', () => {
const introspection = introspectionFromSchema(dummySchema);
const someDirectiveIntrospection = introspection.__schema.directives[0];
expect(someDirectiveIntrospection).to.deep.include({
name: 'SomeDirective',
args: [],
});
delete someDirectiveIntrospection.args;
expect(() => buildClientSchema(introspection)).to.throw(
'Introspection result missing directive args: { name: "SomeDirective",',
);
});
});
describe('very deep decorators are not supported', () => {
it('fails on very deep (> 7 levels) lists', () => {
const schema = buildSchema(`
type Query {
foo: [[[[[[[[String]]]]]]]]
}
`);
const introspection = introspectionFromSchema(schema);
expect(() => buildClientSchema(introspection)).to.throw(
'Decorated type deeper than introspection query.',
);
});
it('fails on a very deep (> 7 levels) non-null', () => {
const schema = buildSchema(`
type Query {
foo: [[[[String!]!]!]!]
}
`);
const introspection = introspectionFromSchema(schema);
expect(() => buildClientSchema(introspection)).to.throw(
'Decorated type deeper than introspection query.',
);
});
it('succeeds on deep (<= 7 levels) types', () => {
// e.g., fully non-null 3D matrix
const sdl = dedent`
type Query {
foo: [[[String!]!]!]!
}
`;
expect(cycleIntrospection(sdl)).to.equal(sdl);
});
});
describe('prevents infinite recursion on invalid introspection', () => {
it('recursive interfaces', () => {
const sdl = `
type Query {
foo: Foo
}
type Foo implements Foo {
foo: String
}
`;
const schema = buildSchema(sdl, { assumeValid: true });
const introspection = introspectionFromSchema(schema);
expect(introspection.__schema.types[1]).to.deep.include({
name: 'Foo',
interfaces: [{ kind: 'OBJECT', name: 'Foo', ofType: null }],
});
expect(() => buildClientSchema(introspection)).to.throw(
'Expected Foo to be a GraphQL Interface type.',
);
});
it('recursive union', () => {
const sdl = `
type Query {
foo: Foo
}
union Foo = Foo
`;
const schema = buildSchema(sdl, { assumeValid: true });
const introspection = introspectionFromSchema(schema);
expect(introspection.__schema.types[1]).to.deep.include({
name: 'Foo',
possibleTypes: [{ kind: 'UNION', name: 'Foo', ofType: null }],
});
expect(() => buildClientSchema(introspection)).to.throw(
'Expected Foo to be a GraphQL Object type.',
);
});
});
});