mirror of
https://github.com/atulmy/gql-query-builder.git
synced 2026-04-25 23:55:55 +03:00
[GH-ISSUE #13] support for union types #102
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/gql-query-builder#102
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @albertalquisola on GitHub (May 28, 2019).
Original GitHub issue: https://github.com/atulmy/gql-query-builder/issues/13
is there support for unions and/or interfaces? one of my api calls returns
contentandcontentis a union type that can return diff types of models.Example desired query output:
@atulmy commented on GitHub (May 28, 2019):
@bebraw / @toadkicker any ideas on Unions / Interfaces?
@toadkicker commented on GitHub (May 28, 2019):
#11 will fix this =)
@atulmy commented on GitHub (May 28, 2019):
@toadkicker Can you give an example here for @albertalquisola use case?
@toadkicker commented on GitHub (May 28, 2019):
https://github.com/NowServing/gql-query-builder/blob/appsync_support/src/adapters/DefaultQueryAdapter.ts#L112
You can basically attack this however you want by creating your own adapter. I'm guessing this is a conditional thing you want, and so one approach could change the adapter to look for a unions flag in the querybuilder options.
@albertalquisola commented on GitHub (Jun 1, 2019):
Thanks for being responsive @atulmy and @toadkicker. For my 2 cents, i'd love for the api to be something like this:
I'll also look over the adapter pr as well and see how flexible it is
@toadkicker commented on GitHub (Jun 2, 2019):
The idea is that the adapter maintains the same documented API that the query builder adheres to. A custom adapter is just a Javascript class that implements the query/mutation adapter interface. Another way to say it is the adapter is the engine of the output, and for the engine to work it needs to have the right inputs.
In @albertalquisola particular use case consider
...carin your fields., and then creating a custom adapter (it can extend from the default one) that outputs unions based on...provided in there. Or even simpler don't worry about detecting it, just hard code it to use the custom adapter when called.@albertalquisola commented on GitHub (Jun 3, 2019):
@toadkicker, I get the concept behind the interface adapter, but could you post a pseudocode example?
@toadkicker commented on GitHub (Jun 5, 2019):
Can just make
UnionAdapter, and change from the default:@atulmy commented on GitHub (Jun 10, 2019):
@albertalquisola let us know if the adapter example was of help
@Wurielle commented on GitHub (Mar 29, 2021):
Not too pretty but it does the trick:
operationTemplatemethod with the following:Hope this helps some people that were struggling with unions like myself.
Note: this solution isn't 100% complete but it should help kickstart your union needs 😄
Edit: here's the full adapter file: UnionQueryAdapter.ts