react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

Side error on cache update in react-apollo 3.0.0-beta.4

Open eddig opened this issue 7 years ago • 2 comments

Intended outcome: The cache should be updated without errors.

      update: cache => {
        // Update tagsMeta field on Profile
        try {
          const cachedData = cache.readQuery({
            query: PROFILE_TAGS_META_QUERY,
            variables: {
              id: profileId
            }
          })

          // For the narrowing down the problem scope,
          // we don't do anything with the cached data,
          // but there was my cache updating code

          cache.writeQuery({
            query: PROFILE_TAGS_META_QUERY,
            variables: {
              id: profileId
            },
            cachedData
          })
        } catch (error) {
          console.log(error)
        }
      }

Actual outcome: In the provided code I removed the cache update logic, but the error still happens. When the cache updating code there all works well (cache updated, components get fresh data) except the error: image I investigated it a bit and looks like the result field for the ROOT_QUERY is undefined. Then apollo client tries to get the Profile field from the result but can't. CleanShot 2019-07-26 at 12 14 37@2x

How to reproduce the issue: I'll try to reproduce it and update this issue later.

Version

System: OS: macOS 10.14.6 Binaries: Node: 10.15.0 - ~/.nvm/versions/node/v10.15.0/bin/node Yarn: 1.17.3 - /usr/local/bin/yarn npm: 6.4.1 - ~/.nvm/versions/node/v10.15.0/bin/npm Browsers: Chrome: 75.0.3770.142 Safari: 12.1.2 npmPackages: apollo-cache-inmemory: ^1.6.2 => 1.6.2 apollo-client: ^2.6.3 => 2.6.3 apollo-link: ^1.2.12 => 1.2.12 apollo-link-context: ^1.0.18 => 1.0.18 apollo-link-http: ^1.5.15 => 1.5.15 react-apollo: 3.0.0-beta.4 => 3.0.0-beta.4

eddig avatar Jul 26 '19 08:07 eddig

It was my mistake, I set the cachedData field at the cache.writeQuery function arguments instead of data 🤦‍♂️

eddig avatar Jul 26 '19 09:07 eddig

By the way, it may be worth to check that the required fields are set for the writeQuery function

eddig avatar Jul 26 '19 09:07 eddig