@@ -26,6 +26,7 @@ import {
26
26
Arg ,
27
27
Authorized ,
28
28
Field ,
29
+ FieldResolver ,
29
30
InputType ,
30
31
InterfaceType ,
31
32
Mutation ,
@@ -107,6 +108,15 @@ describe("typeDefs and resolvers", () => {
107
108
sampleType3StringField ! : string ;
108
109
}
109
110
111
+ @ObjectType ( "SampleType__4" )
112
+ class SampleType4 {
113
+ @Field ( )
114
+ sampleInterfaceStringField ! : string ;
115
+
116
+ @Field ( )
117
+ sampleType4StringField ! : string ;
118
+ }
119
+
110
120
@InputType ( )
111
121
class SampleInput {
112
122
@Field ( )
@@ -241,8 +251,26 @@ describe("typeDefs and resolvers", () => {
241
251
}
242
252
243
253
pubSub = createPubSub ( ) ;
254
+
255
+ @Service ( )
256
+ @Resolver ( ( ) => SampleType4 )
257
+ class SampleObjectTypeWithDoubleUnderscoreInNameResolver {
258
+ @FieldResolver ( ( ) => String )
259
+ sampleResolvedField ( ) : string {
260
+ return "sampleResolvedField" ;
261
+ }
262
+
263
+ @Query ( ( ) => SampleType4 )
264
+ async sampleQueryOnObjectTypeWithDoubleUnderScore ( ) : Promise < SampleType4 > {
265
+ const type4 = new SampleType4 ( ) ;
266
+ type4 . sampleInterfaceStringField = "sampleInterfaceStringField" ;
267
+ type4 . sampleType4StringField = "sampleType4StringField" ;
268
+ return type4 ;
269
+ }
270
+ }
271
+
244
272
( { typeDefs, resolvers } = await buildTypeDefsAndResolvers ( {
245
- resolvers : [ SampleResolver ] ,
273
+ resolvers : [ SampleResolver , SampleObjectTypeWithDoubleUnderscoreInNameResolver ] ,
246
274
authChecker : ( ) => false ,
247
275
pubSub,
248
276
container : Container ,
@@ -286,6 +314,10 @@ describe("typeDefs and resolvers", () => {
286
314
const sampleType2 = schemaIntrospection . types . find (
287
315
it => it . name === "SampleType2" ,
288
316
) as IntrospectionObjectType ;
317
+ const sampleType4 = schemaIntrospection . types . find (
318
+ it => it . name === "SampleType__4" ,
319
+ ) as IntrospectionObjectType ;
320
+
289
321
const sampleType1StringField = sampleType1 . fields . find (
290
322
it => it . name === "sampleType1StringField" ,
291
323
) ! ;
@@ -299,6 +331,7 @@ describe("typeDefs and resolvers", () => {
299
331
expect ( sampleType1 . interfaces ) . toHaveLength ( 1 ) ;
300
332
expect ( sampleType1 . interfaces [ 0 ] . name ) . toBe ( "SampleInterface" ) ;
301
333
expect ( sampleType2StringField . deprecationReason ) . toBe ( "sampleType2StringFieldDeprecation" ) ;
334
+ expect ( sampleType4 . fields ) . toHaveLength ( 3 ) ;
302
335
} ) ;
303
336
304
337
it ( "should generate input type" , async ( ) => {
@@ -356,7 +389,7 @@ describe("typeDefs and resolvers", () => {
356
389
it => it . name === schemaIntrospection . queryType . name ,
357
390
) as IntrospectionObjectType ;
358
391
359
- expect ( queryType . fields ) . toHaveLength ( 8 ) ;
392
+ expect ( queryType . fields ) . toHaveLength ( 9 ) ;
360
393
} ) ;
361
394
362
395
it ( "should generate mutations" , async ( ) => {
@@ -574,6 +607,26 @@ describe("typeDefs and resolvers", () => {
574
607
expect ( enumValue ) . toBe ( "OptionTwoString" ) ;
575
608
} ) ;
576
609
610
+ it ( "should properly execute field resolver for object type with two underscores NOT in the beginning" , async ( ) => {
611
+ const document = gql `
612
+ query {
613
+ sampleQueryOnObjectTypeWithDoubleUnderScore {
614
+ sampleResolvedField
615
+ sampleInterfaceStringField
616
+ sampleType4StringField
617
+ }
618
+ }
619
+ ` ;
620
+
621
+ const { data } = await execute ( { schema, document } ) ;
622
+
623
+ expect ( data ! . sampleQueryOnObjectTypeWithDoubleUnderScore ) . toEqual ( {
624
+ sampleResolvedField : "sampleResolvedField" ,
625
+ sampleInterfaceStringField : "sampleInterfaceStringField" ,
626
+ sampleType4StringField : "sampleType4StringField" ,
627
+ } ) ;
628
+ } ) ;
629
+
577
630
it ( "should properly run subscriptions" , async ( ) => {
578
631
const document = gql `
579
632
subscription {
0 commit comments