question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TypeScript] Missing type generation for a union that only resolves __typename

See original GitHub issue

Describe the bug If you only query a union for the __typename, codegen doesn’t generate a type but still references it. See example: screen shot 2019-01-04 at 15 57 06

To Reproduce Steps to reproduce the behavior:

  1. Write a schema containing a union
  2. 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dotansimhacommented, Mar 18, 2019

Fixed in the recent refactor 😃

1reaction
dotansimhacommented, Jan 6, 2019

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 (use Pick and build a single type only, instead of namespace with multiple interfaces), and we also implemented there a solution for __typename fields).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found