Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sudden error: Encountered a sub-selection on the query, but the store doesn't have \ an object reference #4125

Closed
soniachan opened this issue Nov 9, 2018 · 15 comments

Comments

@soniachan
Copy link

The following error was hit suddenly since around 10 days ago..
A simple mutation and refetchQuery was made
this.apollo.mutate({ mutation: GraphQL.Mutation.updateAccount, refetchQueries: [{ query: GraphQL.Query.accountQuery, variables: { filter: this.account.id, } }], variables: { accountId: this.account.id } })

Encountered a sub-selection on the query, but the store doesn't have
an object reference. This should never happen during normal use unless you have custom code
that is directly manipulating the store; please file an issue.

Does anyone have any idea to fix this error?
My inmemorycache was set with
cache: new InMemoryCache({ dataIdFromObject: object => object['id'] || defaultDataIdFromObject(object) })

@Karsens
Copy link

Karsens commented Nov 10, 2018

I got the same problem. My app always worked until I reinstalled everything today. Running

"apollo-boost": "^0.1.6",
"apollo-cache-redux": "^0.1.0",
"apollo-client": "^2.3.1",
"apollo-link-redux": "^0.2.1",
"expo": "^30.0.0",
"graphql": "^0.13.2",
"graphql-tag": "^2.9.2",
"react": "16.3.1",
"react-apollo": "^2.1.4",
"react-native": "https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz"

@rajit
Copy link

rajit commented Nov 10, 2018

I saw this problem today after nuking node_modules and reinstalling. Not sure yet why it's happening, but I seem to have gotten rid of the problem by running:

npm install --no-save [email protected]

@Karsens
Copy link

Karsens commented Nov 11, 2018

I solved it by using inmemorycache
`const cache2 = new InMemoryCache();``

instead of my Redux Cache

const cache = new ReduxCache({ store });

@soniachan
Copy link
Author

I saw this problem today after nuking node_modules and reinstalling. Not sure yet why it's happening, but I seem to have gotten rid of the problem by running:

npm install --no-save [email protected]

I have also locked the version to [email protected]
Possible that the error was caused by this commit?
a668a6f#diff-fe50f840c179cc1955e7a0dac67e2097

@soniachan
Copy link
Author

I solved it by using inmemorycache
`const cache2 = new InMemoryCache();``

instead of my Redux Cache

const cache = new ReduxCache({ store });

My code was already using InMemoryCache, however the error persists when using apollo-utilities with version 1.0.24 +

@rajit
Copy link

rajit commented Nov 12, 2018

I have also locked the version to [email protected]
Possible that the error was caused by this commit?
a668a6f#diff-fe50f840c179cc1955e7a0dac67e2097

I don't know, but nice find @soniachan!

@kommander
Copy link

I can confirm the problem exists since 1.0.24. When using yarn, going with selective dependency resolution works fine. Thanks @soniachan.

@sacummings91
Copy link

sacummings91 commented Nov 14, 2018

Hey guys, ran into the same bug over here. Seemingly out of nowhere. Based on @rajit and @soniachan comments we experimented with adding apollo-utilities 1.0.22 to our dependencies. Which also worked for us. But ultimately our fix involved updating apollo-cache-inmemory and apollo-client to latest versions. We were on 1.2.6 and 2.3.7 respectively.

@mechanical-turk
Copy link
Contributor

we are also experiencing this issue. we recently nuked our node_modules and re-installed our packages. some packages ended up being resolved differently than they used to. this eventually introduced this current issue. with all the apollo + graphql packages we are using, and all the internal dependencies that they bring, we really found ourselves in a pickle. We tried a bunch of tricks to no avail, including re-evaluating all of our dependencies, and yarn resolutions. We'd be very grateful for anyone who'd offer some help here. FYI, here are the package versions we're using:

apollo-cache-inmemory": "1.1.11",
"apollo-client": "2.4.6",
"apollo-link": "1.2.3",
"apollo-link-http": "1.5.5",
"apollo-utilities": "1.0.22",
"react-apollo": "2.3.1",
"graphql": "0.13.1",
"graphql-anywhere": "4.1.7",
"graphql-tag": "2.10.0",

@annezhou920
Copy link

@sacummings91 tip helped

yarn upgrade [email protected] did the trick for me

@aislanmiranda
Copy link

@ sacummings91 tip ajudou

yarn upgrade [email protected] fez o truque para mim

My problem was solved, thank you.

@bcandullo
Copy link

Moving from 1.2 to 1.3 solved the issue. For those who still use npm: npm update apollo-cache-inmemory

agentdave added a commit to cybera/synthi that referenced this issue Dec 3, 2018
Props to Alecia for tracking down the discussion about:
"Encountered a sub-selection on the query, but the store
doesn't have an object reference.":

apollographql/apollo-client#4125

We weren't directly using apollo-cache-inmemory, which was
the workaround suggested here. But we were using older
versions of apollo-boost, from which we were getting the
InMemoryCache object. They have probably updated since.
@gferreri
Copy link

I am also suddenly seeing this problem with [email protected]. I cannot easily upgrade to 1.3.0+ because doing so breaks rendering of updates after mutations in my application. But I suddenly can't run any unit tests that use MockedProvider or I see this error:

Encountered a sub-selection on the query, but the store doesn't have an object reference. This should never happen during normal use unless you have custom code that is directly manipulating the store; please file an issue.

   98 |       mock3.result.data.someData = data //mock2.result.data.someData
   99 | 
> 100 |       const parent = mount(
      |                      ^
  101 |         <MockedProvider mocks={[mock1, mock2, mock3]} addTypename={false} >
  102 |           <MyComponent userCanEdit={true}/>
  103 |         </MockedProvider>

  at assertIdValue (node_modules/apollo-cache-inmemory/src/readFromStore.ts:218:11)
  at readStoreResolver (node_modules/apollo-cache-inmemory/src/readFromStore.ts:69:3)
  at executeField (node_modules/graphql-anywhere/lib/bundle.esm.js:71:18)
  at node_modules/graphql-anywhere/lib/bundle.esm.js:28:31
      at Array.forEach (<anonymous>)
  at executeSelectionSet (node_modules/graphql-anywhere/lib/bundle.esm.js:23:29)
  at graphql (node_modules/graphql-anywhere/lib/bundle.esm.js:18:12)
  at diffQueryAgainstStore (node_modules/apollo-cache-inmemory/src/readFromStore.ts:198:18)
  at InMemoryCache.Object.<anonymous>.InMemoryCache.diff (node_modules/apollo-cache-inmemory/src/inMemoryCache.ts:119:12)
  at QueryManager.Object.<anonymous>.QueryManager.fetchQuery (node_modules/src/core/QueryManager.ts:340:13)
  at QueryManager.Object.<anonymous>.QueryManager.startQuery (node_modules/src/core/QueryManager.ts:891:10)
  at ObservableQuery.Object.<anonymous>.ObservableQuery.setUpQuery (node_modules/src/core/ObservableQuery.ts:598:23)
  at ObservableQuery.Object.<anonymous>.ObservableQuery.onSubscribe (node_modules/src/core/ObservableQuery.ts:557:43)
  at node_modules/src/core/ObservableQuery.ts:92:12
  at new Subscription (node_modules/zen-observable/lib/Observable.js:183:34)
  at ObservableQuery.subscribe (node_modules/zen-observable/lib/Observable.js:262:14)
  at Query._this.startQuerySubscription (node_modules/react-apollo/react-apollo.umd.js:290:65)
  at Query.Object.<anonymous>.Query.componentDidMount (node_modules/react-apollo/react-apollo.umd.js:377:18)
  at CallbackQueue.notifyAll (../../node_modules/react-dom/lib/CallbackQueue.js:74:22)
  at ReactReconcileTransaction.close (../../node_modules/react-dom/lib/ReactReconcileTransaction.js:78:26)
  at ReactReconcileTransaction.closeAll (../../node_modules/react-dom/lib/Transaction.js:207:25)
  at ReactReconcileTransaction.perform (../../node_modules/react-dom/lib/Transaction.js:154:16)
  at batchedMountComponentIntoNode (../../node_modules/react-dom/lib/ReactMount.js:124:15)
  at ReactDefaultBatchingStrategyTransaction.perform (../../node_modules/react-dom/lib/Transaction.js:141:20)
  at Object.batchedUpdates (../../node_modules/react-dom/lib/ReactDefaultBatchingStrategy.js:60:26)
  at Object.batchedUpdates (../../node_modules/react-dom/lib/ReactUpdates.js:95:27)
  at Object._renderNewRootComponent (../../node_modules/react-dom/lib/ReactMount.js:317:18)
  at Object._renderSubtreeIntoContainer (../../node_modules/react-dom/lib/ReactMount.js:399:32)
  at Object.render (../../node_modules/react-dom/lib/ReactMount.js:420:23)
  at Object.render (../../node_modules/enzyme-adapter-react-15/build/ReactFifteenAdapter.js:190:50)
  at new ReactWrapper (../../node_modules/enzyme/build/ReactWrapper.js:134:16)
  at mount (../../node_modules/enzyme/build/mount.js:21:10)

@abernix
Copy link
Member

abernix commented Jul 12, 2019

I'm going to close this issue since it hasn't received a lot of traction recently and seems to be fixed by a new version. It sounds like upgrading to the latest release is the best way to resolve this, though of course the feasibility of doing that upgrade is project specific.

If this is still a problem, we welcome anyone who is experiencing the problem (or anyone who comes across this issue and is able to assist) to build a reproduction of the problem into a runnable CodeSandbox reproduction](https://codesandbox.io/), using the latest versions of the appropriate packages, and sharing the link to that reproduction in this issue.

I'm happy to re-open if this is still occurring and someone can provide a reproduction, though a new issue which references this issue is probably best. Thanks!

@abernix abernix closed this as completed Jul 12, 2019
@clayrisser
Copy link

clayrisser commented Dec 6, 2019

I have fixed this bug in apollo-cache-redux. Since apollo-cache-redux is deprecated, you can now use @codejamninja/apollo-cache-redux.

npm install --save @codejamninja/apollo-cache-redux
import { ReduxCache, apolloReducer } from '@codejamninja/apollo-cache-redux';

https://github.com/codejamninja/apollo-cache-redux
https://www.npmjs.com/package/@codejamninja/apollo-cache-redux

This fixes the following issues
rportugal/apollo-cache-redux#27
rportugal/apollo-cache-redux#35

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests