Union query requests in client code with conditional fragments
See original GitHub issueI am trying to run a query returning a union type (e.g. the union Vehicle = Car | Bike).
Is there a way to run this query with the current library? In a raw GraphQL call this would be achieved using conditional fragments like so:
query allVehicles {
allVehicles {
...on Car {
brand
}
...on Bike {
weight
}
}
}
I can’t seem to find a way to run the query allVehicles with the current library. Car and Bike both extend the class Vehicle, but Vehicle is a completely empty stub class.
I would expect to have a VehicleUnionResponseProjection with builder options like “.onCar(CarResponseProjection)” and ".onBike(BikeResponseProjection). Would this be possible? Or is there even currently a way to achieve this with a different apporach?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Unions and interfaces - Apollo GraphQL Docs
This query uses inline fragments to fetch a Result 's title (if it's a Book ) or its name (if it's an Author...
Read more >Nested Fragment on Union type field removes data ... - GitHub
When using nested fragments on a union type, the properties from the subfragments are removed from the response without warning or error, ...
Read more >GraphQL query, use fragment depending on some condition ...
The task is to request only metrics that can be viewed by the user. React application is using graphQL file loader and it...
Read more >How to query your schema with GraphQL fragments
A fragment is basically a reusable piece of query. In GraphQL, you often need to query for the same data fields in different...
Read more >Use a union query to combine multiple queries into a single ...
If you've never created a union query before, you might find it useful to first study a working example in the Northwind Access...
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 Free
Top 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
The feature will be released next week. Stay tuned! 😃
@kobylynskyi It is already possible to define custom serializer with
customAnnotationsMapping
(but I may be wrong).For instance, the configuration
generates the following code :
So, the only need is to add
__typename
to the projection of the union and generate the union class. For instance, like :