[TypeScript] Missing type generation for a union that only resolves __typename
See original GitHub issueDescribe the bug
If you only query a union for the __typename
, codegen doesn’t generate a type but still references it. See example:
To Reproduce Steps to reproduce the behavior:
- Write a schema containing a union
- Query for the union
__typename
only
Expected behavior
A type with only the __typename
should be generated. I.e. in this case the generated file should also contain:
export type UserUnion = {
__typename: "OneUnion" | "TwoUnion";
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Unions and interfaces - Apollo GraphQL Docs
Unions and interfaces are abstract GraphQL types that enable a schema field to return one of multiple object types. Union type.
Read more >Handbook - Unions and Intersection Types - TypeScript
How to use unions and intersection types in TypeScript. ... If we have a value that is a union type, we can only...
Read more >typescript-cheatsheet - GitHub Pages
A set of TypeScript related notes used for quick reference. The cheatsheet contains references to types, classes, decorators, and many other TypeScript ......
Read more >GraphQL specification
5.3.1Field Selections on Objects, Interfaces, and Unions Types ... GraphQL services which only seek to provide GraphQL query execution may choose to only...
Read more >Jackson Json - @JsonTypeInfo, using Logical Type Name ...
In that case name will then need to be separately resolved to actual concrete type (Class) via @JsonSubTypes and @JsonTypeName annotations. @ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in the recent refactor 😃
Thanks for reporting if @csoLs ! We are filtering
__typename
and ignoring it from the fields list. It requires a more complex solution.At the moment we are looking for refactoring the typescript packages, and use the same approach as
flow
plugins (usePick
and build a single type only, instead of namespace with multiple interfaces), and we also implemented there a solution for__typename
fields).