New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple Tables (Unions) #47
Comments
Unfortunately there is no support for union types right now. We avoided this feature since there really is no obvious way to automatically union two types with different tables. However, the need has arisen. What we envision is creating a SQL view which unions the two tables, and telling the GraphQL union type to query that view. const X = new GraphQLUnionType({
types: [ Y1, Y2 ],
resolveType: fn() {...},
sqlView: 'Y'
}) CREATE VIEW Y AS
SELECT column_name(s) FROM Y1
UNION ALL
SELECT column_name(s) FROM Y2; Would this work for your use case? Could you elaborate on the use case a bit more? We're curious why you're using GraphQL union types. |
A view should only be necessary when there is a need to sort those. In all other cases simply running two queries and merging the results into the same list is quite sufficient. A view might be more idiomatic with respect to SQL but that would also require a potentially high number of columns in the view since the types might not have overlapping fields. One of our cases for example, is a 'children field which is resolved using a shared field If this is not required by other users I think any work done here should be as minimal as possible though just to get the idea out and validated. |
Yeah, creating views that union very disjoint tables is ugly. For now the best way to handle it is a separate, hand-written query in your resolver. |
Union and Interface types are now possible. It's still not easy to do with incongruous tables, but it's possible. Certainly open to feedback. Feel free to open new issue with suggestions. docs |
We have a data schema where a table X can reference either table Y1 or Y2. In GQL the resolve function thus resolves either Y1 or Y2 which we put into a union Y. In that case the query function would have to execute a query on Y1 and Y2 the fields in Y1 and Y2 are a little different (1 and 2 are respective major versions of the tables. eg. one might have a field the other might not or it might be of an incompatible type).
Is something like this expressible to join monster ?
The text was updated successfully, but these errors were encountered: