Feature Request: Support graphql union types
See original GitHub issueCurrently the only method to do query multiple objects in the same time is to define an custom sql function:
CREATE OR REPLACE FUNCTION search(text TEXT)
RETURNS SETOF search_trigger LANGUAGE sql STABLE AS $$
SELECT id, name,height, NULL AS primary_function, NULL AS length, 'human' AS type FROM humans
WHERE (...)
UNION ALL
SELECT id, name, NULL AS height, primary_function, NULL AS length, 'droid' AS type FROM droids
WHERE (...)
UNION ALL
SELECT id, name, NULL AS height, NULL AS primary_function, length, 'starship' AS type FROM starships
WHERE (...)
$$
while in the front end we query the search_trigger
query {
search(text: "an") {
__typename
id
name
height
primary_function
length
type
}
}
While this should work, we have another type search_trigger
instead of article
and user
in the front end, which can cause many inconveniences, e.g. write new interface and types, inconsistency in local store, etc. It will be good to have support for union type so that we can query with:
query {
search(text: "an") {
__typename
... on Human {
name
height
}
... on Droid {
name
primaryFunction
}
... on Starship {
name
length
}
}
}
Database schema in the examples is borrowed from https://graphql.org/learn/schema/#union-types.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:105
- Comments:13
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 >GraphQL union/interface ETA? - Fauna Forums
I'm planning a project that will be leveraging FaunaDB + GraphQL API (technology that has me VERY excited!), but find the lack of...
Read more >Doing More With GraphQL: Interfaces and Unions - Dgraph Blog
Learn how to use GraphQL's interface and union types. ... like a new feature or requirements to support new types of requests from...
Read more >Getting the Best of TypeScript and GraphQL: Union Types
GraphQL is a query language that is used to define the API of a server. Like TypeScript or even Go language, GraphQL supports...
Read more >GraphQL Unions – Customize your results!
Unions are abstract GraphQL types that enable a schema field to return one of multiple object types. Not really sure what that means?...
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
+1, Ran into this limitation as well, would love union type support to be added to Hasura.
I was just beginning to lean into Union types heavily in our Rails portion of the graph only to find out Hasura is lacking this support given how coupled it is to the database as source of truth. Union types and Interfaces have started becoming rather helpful. I’d love to see something announced as our plan is to move even more to Hasura.