@@ -94,6 +94,31 @@ public Object get(DataFetchingEnvironment environment) {
9494 }
9595 }
9696
97+ @ GraphQLDescription ("Object with different GraphQL name" )
98+ @ GraphQLName ("DifferentObject" )
99+ public static class DifferentNameTestObject {
100+ @ GraphQLField
101+ public String field () {
102+ return "different" ;
103+ }
104+
105+ }
106+
107+ @ GraphQLTypeExtension (GraphQLExtensionsTest .DifferentNameTestObject .class )
108+ public static class DifferentNameTestObjectExtension {
109+ private final DifferentNameTestObject obj ;
110+
111+ public DifferentNameTestObjectExtension (DifferentNameTestObject obj ) {
112+ this .obj = obj ;
113+ }
114+
115+ @ GraphQLField
116+ public String field2 () {
117+ return obj .field () + " field2" ;
118+ }
119+
120+ }
121+
97122 @ Test
98123 public void fields () {
99124 GraphQLAnnotations instance = new GraphQLAnnotations ();
@@ -113,6 +138,24 @@ public void fields() {
113138 assertEquals (fields .get (2 ).getType (), GraphQLString );
114139 }
115140
141+ @ Test
142+ public void fieldsDifferentGraphQLName () {
143+ GraphQLAnnotations instance = new GraphQLAnnotations ();
144+ instance .registerTypeExtension (DifferentNameTestObjectExtension .class );
145+ GraphQLObjectHandler graphQLObjectHandler = instance .getObjectHandler ();
146+ GraphQLObjectType object = graphQLObjectHandler .getGraphQLType (GraphQLExtensionsTest .DifferentNameTestObject .class , instance .getContainer ());
147+
148+ List <GraphQLFieldDefinition > fields = object .getFieldDefinitions ();
149+ assertEquals (fields .size (), 2 );
150+
151+ fields = ImmutableList .sortedCopyOf (Comparator .comparing (GraphQLFieldDefinition ::getName ), fields );
152+
153+ assertEquals (fields .get (0 ).getName (), "field" );
154+ assertEquals (fields .get (1 ).getName (), "field2" );
155+ assertEquals (fields .get (0 ).getType (), GraphQLString );
156+ assertEquals (fields .get (1 ).getType (), GraphQLString );
157+ }
158+
116159 @ Test
117160 public void values () {
118161 GraphQLSchema schema = newAnnotationsSchema ().query (TestObject .class ).typeExtension (TestObjectExtension .class ).build ();
@@ -127,6 +170,19 @@ public void values() {
127170 assertEquals (data .get ("field5" ), "test test5" );
128171 }
129172
173+ @ Test
174+ public void valuesDifferentGraphQLName () {
175+ GraphQLSchema schema = newAnnotationsSchema ().query (DifferentNameTestObject .class ).typeExtension (DifferentNameTestObjectExtension .class ).build ();
176+
177+ assertTrue (schema .getCodeRegistry ().hasDataFetcher (FieldCoordinates .coordinates ("DifferentObject" , "field2" )));
178+
179+ ExecutionResult result = GraphQL .newGraphQL ( schema ).build ().execute (
180+ GraphQLHelper .createExecutionInput ( "{field field2}" , new GraphQLExtensionsTest .DifferentNameTestObject () ) );
181+ Map <String , Object > data = result .getData ();
182+ assertEquals (data .get ("field" ), "different" );
183+ assertEquals (data .get ("field2" ), "different field2" );
184+ }
185+
130186 @ Test
131187 public void testDuplicateField () {
132188 GraphQLAnnotations instance = new GraphQLAnnotations ();
@@ -135,4 +191,5 @@ public void testDuplicateField() {
135191 GraphQLAnnotationsException e = expectThrows (GraphQLAnnotationsException .class , () -> graphQLObjectHandler .getGraphQLType (TestObject .class , instance .getContainer ()));
136192 assertTrue (e .getMessage ().startsWith ("Duplicate field" ));
137193 }
194+
138195}
0 commit comments