-
Notifications
You must be signed in to change notification settings - Fork 354
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
Recursive Types #113
Comments
For the above error to occur, the object must reference itself. A schema with "A" referencing "B" and "B" referencing "A" works fine. But "A" referencing "A" breaks. |
How would you query the following? You would need and infinite expanding fragment. query {
node {
parent # This requires fields but it would go on infinitely
}
}
type Node {
parent: Node
} Reading more here: graphql/graphql-spec#91 |
So it is possible to have a schema with recursion like this but you have to get tricky with how you define the fragments or manually define how deep you want to go. This requires that you have more than one field on the object though, which you probably want, ie. an ID graphql/graphql-spec#91 (comment) query {
node { # 1st
id
parent { # 2nd
id
parent { # 3rd
id
}
}
}
type Node {
id: ID!
parent: Node
} This is a valid bug, but we may not be able to easily support it. I will take a look. Thank you for your issue! |
The above data structure is useful for a tree diagram. Yes, queries are required to have a finite number of layers and the same fragment within itself is not allowed. I believe this is also enforced on most(?) client-side frameworks? It is possible to do the above in graphql-java using GraphQLTypeReference(name). |
I'm not sure if it's a related issue, but when I tried to do a workaround (replacing the output with an interface supertype, such as Node), it throws an error: "interfaceType can't be null". i.e. |
Hello, it seems that recursive types (i.e. an object that has a field with the same type) not supported:
class A { fun parent(): A? { // some implementation } }
Causes the following error:
Caused by: graphql.AssertException: type A not found in schema
The text was updated successfully, but these errors were encountered: