Updating an object with a mutation that returns a different type
See original GitHub issueI have a vote
mutation that’s used to upvote different types of documents: posts, comments, etc. Since I want to use a single mutation for all these types I can’t have it return a Post
or Comment
type, so I created a new VoteResult
type. And I’m using dataIdFromObject
, so the update happens automatically as soon as the mutation returns.
The optimistic response works properly (I’m setting the __typename
manually), but when the mutation returns the real result, something goes wrong and the optimistic response is overturned
Could this be because the mutation doesn’t return an object of the same GraphQL type as the object in the store that needs to be updated? In other words, can a mutation that returns type A
be used to update a document of type B
in the store?
By the way I can confirm that if both types are the same (i.e. I change vote
to return Post
object), I’m not seeing any issues.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (7 by maintainers)
Top GitHub Comments
@SachaG some code example when you have a working version of this would be great to see! We should even put it in the documentation since i think many people will run into this.
I did read the documentation, but I didn’t realized the interfaces section also applied to unions, so for some reason it didn’t really click until I found an issue thread somewhere explaining the problem.