Skip to content

SchemaPrinter cannot print union containing GraphQLTypeReference #3434

Description

@twinprime

Describe the bug
SchemaPrinter cannot print union containing GraphQLTypeReference

To Reproduce

val schema = GraphQLUnionType.newUnionType().name("Shape")
                .possibleType(GraphQLTypeReference.typeRef("Circle"))
                .possibleType(GraphQLTypeReference.typeRef("Square"))
                .build()
val printer = SchemaPrinter()
printer.print(schema)

The above code (in Kotlin) results in ClassCastException:

Exception in thread "main" java.lang.ClassCastException: class graphql.schema.GraphQLTypeReference cannot be cast to class graphql.schema.GraphQLUnmodifiedType (graphql.schema.GraphQLTypeReference and graphql.schema.GraphQLUnmodifiedType are in unnamed module of loader 'app')
	at graphql.schema.GraphQLTypeUtil.unwrapAll(GraphQLTypeUtil.java:199)
	at graphql.schema.DefaultGraphqlTypeComparatorRegistry.unwrapElement(DefaultGraphqlTypeComparatorRegistry.java:54)
	at graphql.schema.DefaultGraphqlTypeComparatorRegistry.lambda$sensibleGroupedOrder$0(DefaultGraphqlTypeComparatorRegistry.java:40)
	at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
	at java.base/java.util.TimSort.sort(TimSort.java:220)
	at java.base/java.util.Arrays.sort(Arrays.java:1307)
	at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:353)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at graphql.schema.idl.SchemaPrinter.lambda$unionPrinter$6(SchemaPrinter.java:626)
	at graphql.schema.idl.SchemaPrinter.printSchemaElement(SchemaPrinter.java:1079)
	at graphql.schema.idl.SchemaPrinter.print(SchemaPrinter.java:1052)
	at aero.airlab.common.ktable.support.TestSchemaKt.main(TestSchema.kt:36)
	at aero.airlab.common.ktable.support.TestSchemaKt.main(TestSchema.kt)

This means we cannot define a union with recursive reference.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    keep-openTells Stale Bot to keep PRs and issues open

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions