[Feature Request] Add ability to generate union type resolver based on __typename field
See original GitHub issueIs your feature request related to a problem? Please describe. When using union type with graphql-java-codegen, we need to define a way to tell Jackson how to choose which implementation depending on the data. This step could be generated.
Describe the solution you’d like
The spec (https://graphql.org/learn/schema/#union-types) defines the __typename
field which will be populated with the data type.
It would be possible to generate Jackson annotations & resolver based on the __typename
field.
This behaviour could be linked to a configuration toggle, and could be overwritten by customAnnotationsMapping
configuration.
Describe alternatives you’ve considered Stay with current implementation.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Suggestion: Allow __typename in types returned by resolvers ...
for this. We have a ton of code that branches based on a union's/interface's returned __typename , and being able to select that...
Read more >Abstract Types - GraphQL Nexus
resolveType return type will be typed as a union of string literals matching the GraphQL object type names of all members in the...
Read more >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 >How to resolve union/interface fields with GraphQL and ...
I have an additional complete runnable example of Union types (configured identically to interfaces) available here.
Read more >Handbook - Unions and Intersection Types - TypeScript
Unions with Common Fields ... If we have a value that is a union type, we can only access members that are common...
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
In the case a modelPackageName is empty, I see that it defaults to packageName. And if both modelPackageName & packageName, the class will be generated in the default root package.
Ok for the proposed switch name and default value.
I will send a PR soon.
I will give it a try.