@@ -45,6 +45,7 @@ import {
4545 ResolversMap ,
4646 ResolverObject ,
4747 ResolverOptions ,
48+ FieldResolver ,
4849} from "../../src" ;
4950
5051describe ( "typeDefs and resolvers" , ( ) => {
@@ -104,6 +105,14 @@ describe("typeDefs and resolvers", () => {
104105 sampleType3StringField : string ;
105106 }
106107
108+ @ObjectType ( "SampleType__4" )
109+ class SampleType4 {
110+ @Field ( )
111+ sampleInterfaceStringField : string ;
112+ @Field ( )
113+ sampleType4StringField : string ;
114+ }
115+
107116 @InputType ( )
108117 class SampleInput {
109118 @Field ( )
@@ -236,9 +245,26 @@ describe("typeDefs and resolvers", () => {
236245 }
237246 }
238247
248+ @Service ( )
249+ @Resolver ( of => SampleType4 )
250+ class SampleObjectTypeWithDoubleUnderscoreInNameResolver {
251+ @FieldResolver ( returns => String )
252+ sampleResolvedField ( ) : string {
253+ return "sampleResolvedField" ;
254+ }
255+
256+ @Query ( returns => SampleType4 )
257+ async sampleQueryOnObjectTypeWithDoubleUnderScore ( ) : Promise < SampleType4 > {
258+ const type4 = new SampleType4 ( ) ;
259+ type4 . sampleInterfaceStringField = "sampleInterfaceStringField" ;
260+ type4 . sampleType4StringField = "sampleType4StringField" ;
261+ return type4 ;
262+ }
263+ }
264+
239265 pubSub = new PubSub ( ) ;
240266 ( { typeDefs, resolvers } = await buildTypeDefsAndResolvers ( {
241- resolvers : [ SampleResolver ] ,
267+ resolvers : [ SampleResolver , SampleObjectTypeWithDoubleUnderscoreInNameResolver ] ,
242268 authChecker : ( ) => false ,
243269 pubSub,
244270 container : Container ,
@@ -281,6 +307,10 @@ describe("typeDefs and resolvers", () => {
281307 const sampleType2 = schemaIntrospection . types . find (
282308 it => it . name === "SampleType2" ,
283309 ) as IntrospectionObjectType ;
310+ const sampleType4 = schemaIntrospection . types . find (
311+ it => it . name === "SampleType__4" ,
312+ ) as IntrospectionObjectType ;
313+
284314 const sampleType1StringField = sampleType1 . fields . find (
285315 it => it . name === "sampleType1StringField" ,
286316 ) ! ;
@@ -294,6 +324,7 @@ describe("typeDefs and resolvers", () => {
294324 expect ( sampleType1 . interfaces ) . toHaveLength ( 1 ) ;
295325 expect ( sampleType1 . interfaces [ 0 ] . name ) . toBe ( "SampleInterface" ) ;
296326 expect ( sampleType2StringField . deprecationReason ) . toBe ( "sampleType2StringFieldDeprecation" ) ;
327+ expect ( sampleType4 . fields ) . toHaveLength ( 3 ) ;
297328 } ) ;
298329
299330 it ( "should generate input type" , async ( ) => {
@@ -303,7 +334,8 @@ describe("typeDefs and resolvers", () => {
303334 const sampleInputDefaultStringField = sampleInput . inputFields . find (
304335 it => it . name === "sampleInputDefaultStringField" ,
305336 ) ! ;
306- const sampleInputDefaultStringFieldType = sampleInputDefaultStringField . type as IntrospectionNamedTypeRef ;
337+ const sampleInputDefaultStringFieldType =
338+ sampleInputDefaultStringField . type as IntrospectionNamedTypeRef ;
307339
308340 expect ( sampleInput . kind ) . toBe ( TypeKind . INPUT_OBJECT ) ;
309341 expect ( sampleInput . inputFields ) . toHaveLength ( 2 ) ;
@@ -350,7 +382,7 @@ describe("typeDefs and resolvers", () => {
350382 it => it . name === schemaIntrospection . queryType . name ,
351383 ) as IntrospectionObjectType ;
352384
353- expect ( queryType . fields ) . toHaveLength ( 8 ) ;
385+ expect ( queryType . fields ) . toHaveLength ( 9 ) ;
354386 } ) ;
355387
356388 it ( "should generate mutations" , async ( ) => {
@@ -568,6 +600,26 @@ describe("typeDefs and resolvers", () => {
568600 expect ( enumValue ) . toBe ( "OptionTwoString" ) ;
569601 } ) ;
570602
603+ it ( "should properly execute field resolver for object type with two underscores NOT in the beginning" , async ( ) => {
604+ const document = gql `
605+ query {
606+ sampleQueryOnObjectTypeWithDoubleUnderScore {
607+ sampleResolvedField
608+ sampleInterfaceStringField
609+ sampleType4StringField
610+ }
611+ }
612+ ` ;
613+
614+ const { data } = await execute ( schema , document ) ;
615+
616+ expect ( data ! . sampleQueryOnObjectTypeWithDoubleUnderScore ) . toEqual ( {
617+ sampleResolvedField : "sampleResolvedField" ,
618+ sampleInterfaceStringField : "sampleInterfaceStringField" ,
619+ sampleType4StringField : "sampleType4StringField" ,
620+ } ) ;
621+ } ) ;
622+
571623 it ( "should properly run subscriptions" , async ( ) => {
572624 const document = gql `
573625 subscription {
0 commit comments