Unsure how to resolve `Missing field while writing result` error when using subscriptions
See original GitHub issueWe’ve implement subscriptions in our application using the useSubscription hook and since upgrading from version 3.3.21 to 3.4.7 we’ve started to see errors around Missing field.... To be clear we realize these errors have likely always existed, but now they’re being surfaced.
We see the following error Missing field 'domainObject' while writing result {} on initial page load when the subscription is registered. We believe that this happens because the first response from the subscription is an empty object. The subscriptions themselves work fine, this only seems to be an issue when they’re initially registered. We’d like to resolve this issue and remove the errors from the console, but have so far been unsuccessful.
We tried to update the fetchPolicy and found that setting it to no-cache removed the error, but this stopped the cache from being updated at all, which defeats the purpose.
Shown below is a snippet of the code that we’ve implemented. Some of the subscriptions allow apollo to do the cache updating on its own (OnObjectUpdated) while with others (OnObjectDeleted) we capture the return data and manually make a change to the cache. In both cases we see the Missing field error. For the OnObjectDeleted subscription, we added a guard in our callback function because when the subscription is registered we receive data as an empty object.
subscription OnObjectDeleted {
objectDeleted {
object {
id
}
}
}
const removeObjectFromCache = ({ subscriptionData: { data } }) => {
if (!data || !data.objectDeleted) return;
removeObject(data.objectDeleted.object.id, client);
};
useSubscription(OnObjectDeleted, { onSubscriptionData: removeObjectFromCache });
useSubscription(OnObjectUpdated);
We’re looking to see if anyone has encountered this and if so how it was resolved.
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:75
- Comments:60 (3 by maintainers)
Top Related StackOverflow Question
It’s been 8 monts and no one that works on apollo has replied? This also happens if mutations have missing fields. Just set them to null they are marked as optionel in the schema
Also getting the error using
useQueryandMockedProvider