Skip to content

Commit 40331dd

Browse files
authored
Fix classCastException when using an extension with implements before its base (#2884)
This happens when there is recursion involved.
1 parent 2195538 commit 40331dd

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
import static graphql.schema.GraphQLEnumValueDefinition.newEnumValueDefinition;
9797
import static graphql.schema.GraphQLTypeReference.typeRef;
9898
import static graphql.schema.idl.SchemaGeneratorAppliedDirectiveHelper.buildAppliedDirectives;
99-
import static graphql.schema.idl.SchemaGeneratorAppliedDirectiveHelper.buildDeprecationReason;
10099
import static graphql.schema.idl.SchemaGeneratorAppliedDirectiveHelper.buildDirectiveDefinitionFromAst;
101100
import static java.lang.String.format;
102101
import static java.util.stream.Collectors.toMap;
@@ -548,7 +547,7 @@ private void buildInterfaceTypeInterfaces(BuildContext buildCtx,
548547
});
549548

550549
extensions.forEach(extension -> extension.getImplements().forEach(type -> {
551-
GraphQLInterfaceType interfaceType = buildOutputType(buildCtx, type);
550+
GraphQLNamedOutputType interfaceType = buildOutputType(buildCtx, type);
552551
if (!interfaces.containsKey(interfaceType.getName())) {
553552
interfaces.put(interfaceType.getName(), interfaceType);
554553
}
@@ -658,7 +657,7 @@ private void buildObjectTypeInterfaces(BuildContext buildCtx,
658657
});
659658

660659
extensions.forEach(extension -> extension.getImplements().forEach(type -> {
661-
GraphQLInterfaceType interfaceType = buildOutputType(buildCtx, type);
660+
GraphQLNamedOutputType interfaceType = buildOutputType(buildCtx, type);
662661
if (!interfaces.containsKey(interfaceType.getName())) {
663662
interfaces.put(interfaceType.getName(), interfaceType);
664663
}

src/test/groovy/graphql/schema/idl/SchemaGeneratorTest.groovy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,4 +2506,31 @@ class SchemaGeneratorTest extends Specification {
25062506
}
25072507
25082508
2509+
def "classCastException when interface extension is before base and has recursion"() {
2510+
given:
2511+
def spec = '''
2512+
# order is important, moving extension below type Foo will fix the issue
2513+
extend type Foo implements HasFoo {
2514+
foo: Foo
2515+
}
2516+
2517+
type Query {
2518+
test: ID
2519+
}
2520+
2521+
interface HasFoo {
2522+
foo: Foo
2523+
}
2524+
2525+
type Foo {
2526+
id: ID
2527+
}
2528+
'''
2529+
2530+
when:
2531+
TestUtil.schema(spec)
2532+
2533+
then:
2534+
noExceptionThrown()
2535+
}
25092536
}

0 commit comments

Comments
 (0)