graphql-client
graphql-client copied to clipboard
Missing getting "__typename" variants if user doesn't specify it in Union or Interface, but only Type
description
if schema is like this,
query BadQuery {
badCollection {
__typename
... on BadType {
name
}
}
}
"BadType" causes value: Error("unknown variant BadType, there are no variants", line: 16, column: 52)', if user doesn't specify "BadType" in Union or Interface but only in Type.
Minimal Reproduce: https://github.com/graphql-rust/graphql-client/compare/main...ulwlu:test_multiple_implement?expand=1
Related Issue: https://github.com/graphql-rust/graphql-client/issues/394
Minimal Fix: Just add below in above minimal reproduce.
union Foo = GoodType | BadType
type goodCollection {
items: [Foo]!
}
type badCollection {
items: [Foo]!
}
Remarks
This happens here.
https://github.com/graphql-rust/graphql-client/blob/e79e30c1b5ae96048d3fbf071a7dd201502bb4e2/graphql_client_codegen/src/codegen/selection.rs#L146-L165
Because it doesn't run when context is "Object", it will never run context.push_variant. So, it will never run https://github.com/graphql-rust/graphql-client/blob/e79e30c1b5ae96048d3fbf071a7dd201502bb4e2/graphql_client_codegen/src/codegen/selection.rs#L559-L565 correctly.
So it will create only empty enum, and it didn't expect any tag="__typename", so it causes panic.
what i wanna know
Is there any reason why this only accepts interface and union?
if this is not on purpose, i can make pr.