diff --git a/src/main/java/graphql/annotations/processor/retrievers/GraphQLExtensionsHandler.java b/src/main/java/graphql/annotations/processor/retrievers/GraphQLExtensionsHandler.java index 19363971..a2f49c65 100644 --- a/src/main/java/graphql/annotations/processor/retrievers/GraphQLExtensionsHandler.java +++ b/src/main/java/graphql/annotations/processor/retrievers/GraphQLExtensionsHandler.java @@ -44,6 +44,7 @@ public class GraphQLExtensionsHandler { public List getExtensionFields(Class object, List definedFields, ProcessingElementsContainer container) throws CannotCastMemberException { List fields = new ArrayList<>(); + String typeName = graphQLObjectInfoRetriever.getTypeName(object); if (container.getExtensionsTypeRegistry().containsKey(object)) { for (Class aClass : container.getExtensionsTypeRegistry().get(object)) { for (Method method : graphQLObjectInfoRetriever.getOrderedMethods(aClass)) { @@ -51,7 +52,7 @@ public List getExtensionFields(Class object, List getExtensionFields(Class object, List fields = object.getFieldDefinitions(); + assertEquals(fields.size(), 2); + + fields = ImmutableList.sortedCopyOf(Comparator.comparing(GraphQLFieldDefinition::getName), fields); + + assertEquals(fields.get(0).getName(), "field"); + assertEquals(fields.get(1).getName(), "field2"); + assertEquals(fields.get(0).getType(), GraphQLString); + assertEquals(fields.get(1).getType(), GraphQLString); + } + @Test public void values() { GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).typeExtension(TestObjectExtension.class).build(); @@ -127,6 +170,19 @@ public void values() { assertEquals(data.get("field5"), "test test5"); } + @Test + public void valuesDifferentGraphQLName() { + GraphQLSchema schema = newAnnotationsSchema().query(DifferentNameTestObject.class).typeExtension(DifferentNameTestObjectExtension.class).build(); + + assertTrue(schema.getCodeRegistry().hasDataFetcher(FieldCoordinates.coordinates("DifferentObject", "field2"))); + + ExecutionResult result = GraphQL.newGraphQL( schema ).build().execute( + GraphQLHelper.createExecutionInput( "{field field2}", new GraphQLExtensionsTest.DifferentNameTestObject() ) ); + Map data = result.getData(); + assertEquals(data.get("field"), "different"); + assertEquals(data.get("field2"), "different field2"); + } + @Test public void testDuplicateField() { GraphQLAnnotations instance = new GraphQLAnnotations(); @@ -135,4 +191,5 @@ public void testDuplicateField() { GraphQLAnnotationsException e = expectThrows(GraphQLAnnotationsException.class, () -> graphQLObjectHandler.getGraphQLType(TestObject.class, instance.getContainer())); assertTrue(e.getMessage().startsWith("Duplicate field")); } + }