-
Notifications
You must be signed in to change notification settings - Fork 2k
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
...on UnionType { fields } does not respond with the actual type of data #50
Comments
Okay, So the query becomes:
|
Keeping this open as a note to include this in the full documentation we're working on. |
|
Closing out this issue since it's aging, but continual documentation improvements will help with this kind of confusion. |
Spec: http://facebook.github.io/graphql/#sec-Unions
I find it quite surprising that doing
...on UnionType { fields }
, the response object just contains the fields and nothing about the type of the data being returned.If we take the example in spec further and add a new type video which also has height and width fields:
And then add it to search result union type:
If we had a root query
search(query: "foo")
that returned aGraphQLList(SearchResult)
and did something like:The response could end up looking like this:
How the client is supposed to know what type the results are? I could inspect the returned fields, but that doesn't work when Photo and Video has exactly the same fields. Also it feels kind of hacky.
One solution to this is add a type field for Video, Photo and Person and require the client to request that field also. But is there really a scenario where you don't need this information?
I think what should happen by default is that the value is wrapped with the actual type of each result. For example, the above response would become something like:
With this response, the client can just loop over the results and do something like this:
What do you think?
The text was updated successfully, but these errors were encountered: