From 41383949d29ee5f6fe7e7d05a15dbac410e61481 Mon Sep 17 00:00:00 2001 From: Don Brown Date: Mon, 11 Dec 2017 15:13:21 -0700 Subject: [PATCH 1/2] Fix introspection processing missing implements --- .../introspection/IntrospectionResultToSchema.java | 8 ++++++++ .../IntrospectionResultToSchemaTest.groovy | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/graphql/introspection/IntrospectionResultToSchema.java b/src/main/java/graphql/introspection/IntrospectionResultToSchema.java index 485047d3e6..ccf2072ccc 100644 --- a/src/main/java/graphql/introspection/IntrospectionResultToSchema.java +++ b/src/main/java/graphql/introspection/IntrospectionResultToSchema.java @@ -30,6 +30,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static graphql.Assert.assertNotNull; import static graphql.Assert.assertShouldNeverHappen; @@ -206,6 +207,13 @@ ObjectTypeDefinition createObject(Map input) { ObjectTypeDefinition objectTypeDefinition = new ObjectTypeDefinition((String) input.get("name")); objectTypeDefinition.setComments(toComment((String) input.get("description"))); + if (input.containsKey("interfaces")) { + objectTypeDefinition.getImplements().addAll( + ((List>)input.get("interfaces")).stream() + .map(this::createTypeIndirection) + .collect(Collectors.toList()) + ); + } List> fields = (List>) input.get("fields"); objectTypeDefinition.getFieldDefinitions().addAll(createFields(fields)); diff --git a/src/test/groovy/graphql/introspection/IntrospectionResultToSchemaTest.groovy b/src/test/groovy/graphql/introspection/IntrospectionResultToSchemaTest.groovy index 4ea85363ad..6764ee9d04 100644 --- a/src/test/groovy/graphql/introspection/IntrospectionResultToSchemaTest.groovy +++ b/src/test/groovy/graphql/introspection/IntrospectionResultToSchemaTest.groovy @@ -74,7 +74,11 @@ class IntrospectionResultToSchemaTest extends Specification { } ], "inputFields": null, - "interfaces": [], + "interfaces": [{ + "kind": "INTERFACE", + "name": "Query", + "ofType": null + }], "enumValues": null, "possibleTypes": null } @@ -87,7 +91,7 @@ class IntrospectionResultToSchemaTest extends Specification { def result = astPrinter.printAst(objectTypeDefinition) then: - result == """type QueryType { + result == """type QueryType implements Query { hero( #comment about episode episode: Episode @@ -437,7 +441,7 @@ enum Episode { } #A humanoid creature in the Star Wars universe. -type Human { +type Human implements Character { #The id of the human. id: String! #The name of the human. @@ -451,7 +455,7 @@ type Human { } #A mechanical creature in the Star Wars universe. -type Droid { +type Droid implements Character { #The id of the droid. id: String! #The name of the droid. From a98e7bf1ee76d43672720fcba61917e1c05add6b Mon Sep 17 00:00:00 2001 From: Don Brown Date: Thu, 14 Dec 2017 14:26:09 -0700 Subject: [PATCH 2/2] Fix broken tests --- src/test/groovy/graphql/schema/diff/SchemaDiffTest.groovy | 2 +- src/test/groovy/graphql/schema/idl/SchemaPrinterTest.groovy | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/groovy/graphql/schema/diff/SchemaDiffTest.groovy b/src/test/groovy/graphql/schema/diff/SchemaDiffTest.groovy index 3bf7ff030c..5d87abb28e 100644 --- a/src/test/groovy/graphql/schema/diff/SchemaDiffTest.groovy +++ b/src/test/groovy/graphql/schema/diff/SchemaDiffTest.groovy @@ -228,7 +228,7 @@ class SchemaDiffTest extends Specification { diff.diffSchema(diffSet, chainedReporter) expect: - reporter.breakageCount == 2 // 2 fields removed + reporter.breakageCount == 8 // 2 fields removed from interface, affecting 3 types reporter.breakages[0].category == DiffCategory.MISSING reporter.breakages[0].typeKind == TypeKind.Interface diff --git a/src/test/groovy/graphql/schema/idl/SchemaPrinterTest.groovy b/src/test/groovy/graphql/schema/idl/SchemaPrinterTest.groovy index 1a4dfa6ba1..14e0c7ebbb 100644 --- a/src/test/groovy/graphql/schema/idl/SchemaPrinterTest.groovy +++ b/src/test/groovy/graphql/schema/idl/SchemaPrinterTest.groovy @@ -644,7 +644,7 @@ type TypeE { name: String! } -type Droid { +type Droid implements Character { appearsIn: [Episode]! friends: [Character] id: ID! @@ -653,7 +653,7 @@ type Droid { primaryFunction: String } -type Human { +type Human implements Character { appearsIn: [Episode]! friends: [Character] homePlanet: String