@@ -94,6 +94,31 @@ public Object get(DataFetchingEnvironment environment) {
94
94
}
95
95
}
96
96
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
+
97
122
@ Test
98
123
public void fields () {
99
124
GraphQLAnnotations instance = new GraphQLAnnotations ();
@@ -113,6 +138,24 @@ public void fields() {
113
138
assertEquals (fields .get (2 ).getType (), GraphQLString );
114
139
}
115
140
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
+
116
159
@ Test
117
160
public void values () {
118
161
GraphQLSchema schema = newAnnotationsSchema ().query (TestObject .class ).typeExtension (TestObjectExtension .class ).build ();
@@ -127,6 +170,19 @@ public void values() {
127
170
assertEquals (data .get ("field5" ), "test test5" );
128
171
}
129
172
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
+
130
186
@ Test
131
187
public void testDuplicateField () {
132
188
GraphQLAnnotations instance = new GraphQLAnnotations ();
@@ -135,4 +191,5 @@ public void testDuplicateField() {
135
191
GraphQLAnnotationsException e = expectThrows (GraphQLAnnotationsException .class , () -> graphQLObjectHandler .getGraphQLType (TestObject .class , instance .getContainer ()));
136
192
assertTrue (e .getMessage ().startsWith ("Duplicate field" ));
137
193
}
194
+
138
195
}
0 commit comments