'In GraphQL, how do I filter specific types from a union?
Let's say that I have this query :
searchMedia(term: "puppies") {
... on AudioClip {
duration
}
... on VideoClip {
previewURL
resolution
}
... on Image {
thumbnailURL
}
... on TextSnippet {
teaserText
}
}
But I can let users define which types are returned (e.g. users can specify that they only want audio and video clips, not no text or images). Do I have to create a query for each and every permutations or can I specify some parameter to filter out these types?
Note that I'm using pagination through a MySQL query, so filtering on the client after the results are returned would give unpredictable lists of items.
I was hoping that I could create a filter like
input SearchMediaFilter {
__typename:String
}
but GraphQL complains that it is an internal property. Has anyone got around this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
