Hi! I have a Strawberry GraphQL server that supports sending deferred responses to my Apollo client-based frontend, and queries with deferred fields are working as expected. From this relevant PR and reading the latest code on master, it seems like mutations currently do not really support deferred fields but the Apollo cache is updated correctly for the initial response of a deferred field and then updated again for each subsequent response. Is there any way to use this information to update my frontend without having to rely on the data returned by the mutation?
Sample Mutation:
mutation CreateObject($params: [Param!]) {
createObject(params: $params) {
id
... @defer {
data
}
}
}
What is the recommended way to update my frontend with this newly created object so that I don’t have to wait for the full response from the backend?
you’re right in your analysis - as mutate returns a promise and useMutation relies on that API, we have no way (without changing our apis) of exposing more than one value here - and that will be the last one.
If you know the id of the object being created, you could use useFragment to get to that value early.
Apart from that, all solutions I can think of are inherently hacky: You could use a writeTypePolicy to track on the side what’s written to the cache, or you could use a custom link to observe incoming values - but nothing straightforward for your use case, I’m sorry.
Not as far as I’m aware this point.
As I said, it would require changing the user-facing API, which is quite interruptive to our userbase, and the main idea of a mutation is to invoke a side effect on the server.
Most of our users don’t manually update the cache after a mutation based on the mutation result, but use either passive cache updates from the mutation result or refetchQueries to update their UI after a mutation.
I have to admit that I believe you’re the first person that ever brought it up with us that they wanted to access deferred results from a mutation early (apart from the passive cache updates).
We can consider it in the future, but there are no immediate plans.