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.

[Feature Request] Add ability to generate union type resolver based on __typename field

See original GitHub issue

Is 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:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
gdhordaincommented, Apr 8, 2021

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.

1reaction
gdhordaincommented, Apr 8, 2021

I will give it a try.

Read more comments on GitHub >

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

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