question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unsure how to resolve `Missing field while writing result` error when using subscriptions

See original GitHub issue

We’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:open
  • Created 2 years ago
  • Reactions:75
  • Comments:60 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
tintin10qcommented, Apr 26, 2022

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

9reactions
camilo-perilla-globantcommented, Sep 21, 2021

Also getting the error using useQuery and MockedProvider

"@apollo/client": "^3.4.13"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Apollo client link state "Missing field in {}" when writing to cache?
Im using Apollo Client, Graphcool and React.
Read more >
Why does Apollo Client throw "Missing field" errors when ...
I'm using Apollo Client 3.4.x. When calling writeQuery and passing data that's missing fields specified in the query, I would expect Apollo ...
Read more >
NetSuite Applications Suite - Oracle Help Center
... Running Gulp Commands Results in a Syntax Error · Missing Promo Code on Return ... Writing to Custom Segment Fields on Orders...
Read more >
Creating a Map from SOQL missing field in Map
I am creating a map from a SOQL Query and the map does not have all of the columns in it. I am...
Read more >
Common mistakes when initializing Apollo's local state with ...
When you have a look in the console output of your browser you will see a warning Missing field __typename .... So at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found