ExpediaGroup / graphql-kotlin

Libraries for running GraphQL in Kotlin

Home Page:https://opensource.expediagroup.com/graphql-kotlin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regression from v6: 'didGenerateGraphQLType' fails if the Entity has a @key that is still a GraphQLTypeReference

alex-lange opened this issue · comments

Library Version
7.0.1

Describe the bug
If the schema generator calls didGenerateGraphQLType on an entity with a @key selection set that contains another object, and that object has not yet been added to the schema, then the call to GraphQLTypeUtil.unwrapAll(currentFieldType) in validateFieldSetSelection throws the error

val isExternal = isExternalPath || GraphQLTypeUtil.unwrapAll(currentFieldType).isExternalPath() || currentField.isExternalType()

java.lang.ClassCastException: class graphql.schema.GraphQLTypeReference cannot be cast to class graphql.schema.GraphQLUnmodifiedType

This was not an issue in v6 (or the last version of 7 alpha we used, 7.0.0-alpha.4), and I'm guessing it is from this commit: 5cad531#diff-60a728ab48e454e36c195fd120482f55fe1a9b970006c18cf4cf03bcdb214e05

To Reproduce
This schema gets the schema generator to try to add Child before Parent, which causes the issue:

data class Parent(
  val id: ID,
  val someChild: Child,
)

@KeyDirective(fields = FieldSet("parent { id }"))
data class Child(
  val parent: Parent,
)

class Query {
  fun parent(): Parent = TODO()
}

val schema = toFederatedSchema(
  config = FederatedSchemaGeneratorConfig(
    supportedPackages = listOf("mdg.auth.repro"),
    hooks = FederatedSchemaGeneratorHooks(emptyList()),
  ),
  queries = listOf(TopLevelObject(Query()))
)

Expected behavior
The schema to be generated instead of breaking.