Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interfaces of Interfaces is invalid GraphQL #419

Closed
smyrick opened this issue Oct 2, 2019 · 1 comment · Fixed by #420
Closed

Interfaces of Interfaces is invalid GraphQL #419

smyrick opened this issue Oct 2, 2019 · 1 comment · Fixed by #420
Labels
type: enhancement New feature or request

Comments

@smyrick
Copy link
Contributor

smyrick commented Oct 2, 2019

Library Version
1.0.0

Describe the issue
According to the spec, an interface can not implement another interface. This is not caught by our schema generator but instead just returns the first level interface as the type in the schema.

However there is an outstand RFC into the GraphQL spec to allow this: graphql/graphql-spec#373

Until this is approved and updated we should fail with an exception to better inform schema developers of the limitations when an interface has a supertype that is not @GraphQLIgnored

To Reproduce

This test passes, do we want to make it not pass?

import com.expediagroup.graphql.TopLevelObject
import com.expediagroup.graphql.testSchemaConfig
import com.expediagroup.graphql.toSchema
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull

class InterfaceOfInterfaceTest {

    @Test
    fun `interface of interface`() {
        val queries = listOf(TopLevelObject(InterfaceOfInterfaceQuery()))

        val schema = toSchema(queries = queries, config = testSchemaConfig)

        assertEquals(expected = 1, actual = schema.queryType.fieldDefinitions.size)
        assertEquals(expected = "getClass", actual = schema.queryType.fieldDefinitions.first().name)

        assertNotNull(schema.typeMap["MyClass"])
        assertNotNull(schema.typeMap["SecondLevel"])
        assertNull(schema.typeMap["FirstLevel"])
    }

    interface FirstLevel {
        val id: String
    }

    interface SecondLevel : FirstLevel {
        val name: String
    }

    class MyClass(override val id: String, override val name: String) : SecondLevel

    class InterfaceOfInterfaceQuery {
        fun getClass() = MyClass(id = "1", name = "fooBar")
    }
}

produces

schema {
  query: Query
}

interface SecondLevel {
  id: String!
  name: String!
}

type MyClass implements SecondLevel {
  id: String!
  name: String!
}

type Query {
  getClass: MyClass!
}
@smyrick smyrick added type: bug Something isn't working type: enhancement New feature or request and removed type: bug Something isn't working labels Oct 2, 2019
@smyrick
Copy link
Contributor Author

smyrick commented Oct 2, 2019

Changing this to an enhancement since we still technically generate a valid schema, just in the Kotlin world we are losing some information

smyrick added a commit to smyrick/graphql-kotlin that referenced this issue Oct 2, 2019
Resolves ExpediaGroup#419

According to the spec, an interface can not implement another interface. This is not caught by our schema generator but instead just returns the first level interface as the type in the schema. We are now throwing an exception to help translate this understanding of GraphQL through the Kotlin code
smyrick added a commit to smyrick/graphql-kotlin that referenced this issue Oct 16, 2019
Resolves ExpediaGroup#419

According to the spec, an interface can not implement another interface. This is not caught by our schema generator but instead just returns the first level interface as the type in the schema. We are now throwing an exception to help translate this understanding of GraphQL through the Kotlin code
dariuszkuc pushed a commit that referenced this issue Oct 16, 2019
* Throw exception on multi-level interface

Resolves #419

According to the spec, an interface can not implement another interface. This is not caught by our schema generator but instead just returns the first level interface as the type in the schema. We are now throwing an exception to help translate this understanding of GraphQL through the Kotlin code

* Return superclasses from multiple levels deep
dariuszkuc pushed a commit to dariuszkuc/graphql-kotlin that referenced this issue Aug 5, 2022
* Throw exception on multi-level interface

Resolves ExpediaGroup#419

According to the spec, an interface can not implement another interface. This is not caught by our schema generator but instead just returns the first level interface as the type in the schema. We are now throwing an exception to help translate this understanding of GraphQL through the Kotlin code

* Return superclasses from multiple levels deep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

1 participant