Ability to query interfaces that a union implements
See original GitHub issueWe’re using genql
’s typings on an upcoming app and its been working really well! It fits right in, and typed queries and mutations are awesome!
There’s one area where type support is limited though, and that has to do with interfaces and unions. When querying against a resource that returns a union, you should also be able to query interfaces that the union’s types implement. Currently, it is only possible to query individual types within the union.
Perhaps an example will make this clearer.
So assume this (part of) GraphQL schema
interface ClientError {
message: String!
}
type ClientErrorNameAlreadyTaken implements ClientError {
message: String!
}
type ClientErrorNameInvalid implements ClientError {
message: String!
}
union GenericError =
ClientErrorNameAlreadyTaken
| ClientErrorNameInvalid
type Query {
error: GenericError
}
Here, this query is currently possible:
query q {
error {
... on ClientErrorNameAlreadyTaken { message }
... on ClientErrorNameInvalid { message }
}
}
as
client.query({
error: {
on_ClientErrorNameAlreadyTaken: { message: true }
on_ClientErrorNameInvalid: { message: true }
}
})
However, the following is also a valid query in GraphQL that genql
disallows:
query q {
error {
... on ClientError { message }
}
}
It’d be awesome if genql
could let me query it this way:
client.query({
error: {
on_ClientError: { message: true }
}
})
If I’m being unclear, please let me know!
I’m more than happy to send a PR your way to support this if you like 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Released in 2.4.0
I will work on this, I already know what to change, i also need to clean up tests because now it’s a mess