graphql-zeus
graphql-zeus copied to clipboard
Bug: implemented Interface not working nor properly typed
Problem
- When a union of types which implement an interface is returned, it should be possible to get the concrete types' values using
inline fragment
with theinterface
name instead of theconcrete types
themselves. This is very useful when doing error handling and you don't want to specifically have to handle each case or manually update new error types on the client side. e.g https://blog.logrocket.com/handling-graphql-errors-like-a-champ-with-unions-and-interfaces/
Example issue:
Below should allow interface Node
inline framgenet to get the common field - Id
i.e ...on Node { id true}
Example schema:
interface Node {
id: ID!
}
type User implements Node {
id: ID!
login: String!
}
type Post implements Node {
id: ID!
title: String!
body: String!
}
union UserOrPost = User | Post
type Query {
entity(id: ID!): UserOrPost
}
I agree, I also need this functionality. And I think it should work also if i not use "...on Node" at all. I use following scenario (return type Node instead of UserOrPost):
type Query {
entity(id: ID!): Node
}
If I query for this fragment:
{
entity: [
{ id: "" },
{
__typeName: true,
id: true
}
]
}
the return typescript type should work even without using ...on Node
. But now it returns never
.
should work in 5.2.2
Hi @aexol, thanks for your hard work on this! I just tried using the API, but it didn't seem to work for me. Could you provide some guidance on how to use it correctly, or let me know if there's something I might be missing? Thanks in advance for your help!

PS: I was thinking of this: https://graphql.org/learn/schema/#union-types, where it states that:
"Also, in this case, since Human and Droid share a common interface (Character), you can query their common fields in one place rather than having to repeat the same fields across multiple types: "
could you provide me with your Zeus generated files? I can debug
I see your output is correct right now.
I see now you meant unions sharing an interface
I can think about it of course. Meanwhile, it would help if you typed fields for each union member. Now, this feature works only if you return the interface from the field. I can think of applying the exact mechanism to unions.
that's right, when you return an interface, it works as expected. However, when some or all members of a union implement the same interface, it should be possible to use the interface and get a union of the concrete types with only the fields defined in the interface and the __typename of the respective concrete types 🤔