-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Proposal: Interface implementations should satisfy interface fields #294
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
Comments
This seems like a natural thing to allow. Do you want to open a PR against the specification, that might be the easiest thing to discuss. I don’t imagine it would be too intrusive written correctly 😊 One thing to think about is if we should give a similar treatment to unions. I imagine the best structure for may be to write some general “supertype” validation. |
This would require some pretty significant changes to GraphQL implementations though, right? |
I was just looking through the spec with an eye out for lines I may need to change as part of a PR, and I came across the Object type validation rules, which seem to already describe my proposal here:
It appears that @leebyron defined this behavior in 2015 in this commit with the following message:
Furthermore, this is the wording that appears on Facebook's official GraphQL specification. So am I correct to assume that this is a bug in |
Nope... not a bug, as the test is working as expected. I'll go back and see what other factors may have made this error appear for me in Sorry for the noise! |
Don't be sorry for the noise. We appreciate the attention to detail and the intent. |
I have moved this here from graphql/graphql-js#776.
After opening graphql/graphql-js#720 some time ago, I refactored my schema to work with the current state of GraphQL interfaces. However, this continues to gnaw at me as a real missed opportunity, particularly in allowing general-purpose tools like Relay's Cursor Connection Specification to express their requirements in GraphQL.
Let's imagine the following currently-invalid schema:
Intuitively, this makes sense: both
Dog
andBird
implementPet
. However, the mother and father of aDog
are each aDog
and not a genericPet
. This should be possible, but currently isn't.If this were possible we could do some really cool things. We can continue to query the interface as if each pet's mother was a
Pet
(and not aDog
orBird
):We can also continue to use inline fragments to switch between the types:
But it adds much more convenient and semantically clear querying of a single pet type. We can, for example, directly ask if a dog's parents have displasia, without using an inline fragment to switch on the obvious:
Now, of course this example is a bit oversimple, and the bennefits are marginal and mostly just erganomic. For tooling such as the Relay spec, however, this could be extremely useful.
If this has previously been considered and decided against, I would love to hear some thoughts on why, if just to scratch my itch. If it hasn't yet been considered (or has been filed away under "maybe later") I would love to explore what an implementation might look like!
I opened this issue together with #295, as they each describe a distinct expansion of the GraphQL language. However, both are necessary to create the "higher order interfaces" that open up GraphQL's type system to general purpose tools.
The text was updated successfully, but these errors were encountered: