@@ -20,6 +20,7 @@ import {
20
20
GraphQLUnionType ,
21
21
GraphQLID ,
22
22
GraphQLString ,
23
+ GraphQLEnumType ,
23
24
GraphQLNonNull ,
24
25
GraphQLList ,
25
26
} from '../../type' ;
@@ -70,12 +71,21 @@ const SomeUnionType = new GraphQLUnionType({
70
71
types : [ FooType , BizType ] ,
71
72
} ) ;
72
73
74
+ const SomeEnumType = new GraphQLEnumType ( {
75
+ name : 'SomeEnum' ,
76
+ values : {
77
+ 'ONE' : { value : 1 } ,
78
+ 'TWO' : { value : 2 } ,
79
+ }
80
+ } ) ;
81
+
73
82
const testSchema = new GraphQLSchema ( {
74
83
query : new GraphQLObjectType ( {
75
84
name : 'Query' ,
76
85
fields : ( ) => ( {
77
86
foo : { type : FooType } ,
78
87
someUnion : { type : SomeUnionType } ,
88
+ someEnum : { type : SomeEnumType } ,
79
89
someInterface : {
80
90
args : { id : { type : new GraphQLNonNull ( GraphQLID ) } } ,
81
91
type : SomeInterfaceType
@@ -153,9 +163,15 @@ type Foo implements SomeInterface {
153
163
type Query {
154
164
foo: Foo
155
165
someUnion: SomeUnion
166
+ someEnum: SomeEnum
156
167
someInterface(id: ID!): SomeInterface
157
168
}
158
169
170
+ enum SomeEnum {
171
+ ONE
172
+ TWO
173
+ }
174
+
159
175
interface SomeInterface {
160
176
name: String
161
177
some: SomeInterface
@@ -208,9 +224,70 @@ input NewInputObj {
208
224
type Query {
209
225
foo: Foo
210
226
someUnion: SomeUnion
227
+ someEnum: SomeEnum
228
+ someInterface(id: ID!): SomeInterface
229
+ }
230
+
231
+ enum SomeEnum {
232
+ ONE
233
+ TWO
234
+ }
235
+
236
+ interface SomeInterface {
237
+ name: String
238
+ some: SomeInterface
239
+ }
240
+
241
+ union SomeUnion = Foo | Biz
242
+ ` ) ;
243
+ } ) ;
244
+
245
+ it ( 'extends objects by adding new fields with existing types' , ( ) => {
246
+ const ast = parse ( `
247
+ extend type Foo {
248
+ newField(arg1: SomeEnum!): SomeEnum
249
+ }
250
+
251
+ input NewInputObj {
252
+ field1: Int
253
+ field2: [Float]
254
+ field3: String!
255
+ }
256
+ ` ) ;
257
+ const originalPrint = printSchema ( testSchema ) ;
258
+ const extendedSchema = extendSchema ( testSchema , ast ) ;
259
+ expect ( extendedSchema ) . to . not . equal ( testSchema ) ;
260
+ expect ( printSchema ( testSchema ) ) . to . equal ( originalPrint ) ;
261
+ expect ( printSchema ( extendedSchema ) ) . to . equal (
262
+ `type Bar implements SomeInterface {
263
+ name: String
264
+ some: SomeInterface
265
+ foo: Foo
266
+ }
267
+
268
+ type Biz {
269
+ fizz: String
270
+ }
271
+
272
+ type Foo implements SomeInterface {
273
+ name: String
274
+ some: SomeInterface
275
+ tree: [Foo]!
276
+ newField(arg1: SomeEnum!): SomeEnum
277
+ }
278
+
279
+ type Query {
280
+ foo: Foo
281
+ someUnion: SomeUnion
282
+ someEnum: SomeEnum
211
283
someInterface(id: ID!): SomeInterface
212
284
}
213
285
286
+ enum SomeEnum {
287
+ ONE
288
+ TWO
289
+ }
290
+
214
291
interface SomeInterface {
215
292
name: String
216
293
some: SomeInterface
@@ -253,9 +330,15 @@ type Foo implements SomeInterface {
253
330
type Query {
254
331
foo: Foo
255
332
someUnion: SomeUnion
333
+ someEnum: SomeEnum
256
334
someInterface(id: ID!): SomeInterface
257
335
}
258
336
337
+ enum SomeEnum {
338
+ ONE
339
+ TWO
340
+ }
341
+
259
342
interface SomeInterface {
260
343
name: String
261
344
some: SomeInterface
@@ -348,9 +431,15 @@ union NewUnion = NewObject | NewOtherObject
348
431
type Query {
349
432
foo: Foo
350
433
someUnion: SomeUnion
434
+ someEnum: SomeEnum
351
435
someInterface(id: ID!): SomeInterface
352
436
}
353
437
438
+ enum SomeEnum {
439
+ ONE
440
+ TWO
441
+ }
442
+
354
443
interface SomeInterface {
355
444
name: String
356
445
some: SomeInterface
@@ -399,9 +488,15 @@ interface NewInterface {
399
488
type Query {
400
489
foo: Foo
401
490
someUnion: SomeUnion
491
+ someEnum: SomeEnum
402
492
someInterface(id: ID!): SomeInterface
403
493
}
404
494
495
+ enum SomeEnum {
496
+ ONE
497
+ TWO
498
+ }
499
+
405
500
interface SomeInterface {
406
501
name: String
407
502
some: SomeInterface
@@ -465,9 +560,15 @@ interface NewInterface {
465
560
type Query {
466
561
foo: Foo
467
562
someUnion: SomeUnion
563
+ someEnum: SomeEnum
468
564
someInterface(id: ID!): SomeInterface
469
565
}
470
566
567
+ enum SomeEnum {
568
+ ONE
569
+ TWO
570
+ }
571
+
471
572
interface SomeInterface {
472
573
name: String
473
574
some: SomeInterface
0 commit comments