Tanuj Upreti
Tanuj Upreti

Reputation: 91

Encountered a sub-selection on the query, but the store doesn't have an object reference Apollo Link State

This is my main query to get all data from a server.

Query to get data from server

Then I would like to set this in Apollo link state.

To set in link state here's my resolver.

resolver for link state

This is my client/cache query to get previous cache state.

local client/cache query

I don't know where I'm missing anything on this.

ApolloError.js:37 Uncaught (in promise) Error: Network 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.

Upvotes: 8

Views: 2218

Answers (2)

alexandressh
alexandressh

Reputation: 11

This error might be happening due to apollo-cache-inmemory package version. Try updating the package to the latest version:

npm update apollo-cache-inmemory

This github thread is trying to track the issue and updating the package seems to work just fine: https://github.com/apollographql/apollo-client/issues/4125

Upvotes: 1

Erakk
Erakk

Reputation: 922

You probably have a query setup to fetch a nested object, but you are not requesting anything from that nested object.

In this example, hero has two properties, name of type string and ultimateAbility of type Ability. Ability has name: string and cooldown: number.

With that in mind, the following might give you that error because we are requesting ultimateAbility (our nested object) but we are not telling graph what we want from it:

{
  hero {
    name
    ultimateAbility
  }
}

The correct approach would be to just add which props you want from ultimateAbility:

{
  hero {
    name
    ultimateAbility {
      name
    }
  }
}

My background: I went through this recently and after digging through lots of PRs my team nailed down to this.

Upvotes: 0

Related Questions