Issue with local-only fields

Hi guys,

I’m struggling right now with “local-only fields”.

I followed every single step of the documentation (multiple times) and still run always in the same issue: “Found @client directives in a query but no ApolloClient resolvers were specified. This means ApolloClient local resolver handling has been disabled, and @client directives will be passed through to your link chain.

I’m using @apollo/client 3.3.21.
From my understanding it should work with only a typePolicy in the InMemoryCache settings.

My code:

const cache = new InMemoryCache({
    typePolicies: {
      Thing: {
        fields: {
          clientState: {
            read() {
              return 'myStaticState'
            }
          }
        }
      }
    }
  })
  const apolloClient = new ApolloClient({
    link,
    cache
  })

On Stackoverflow everything is about to add empty resolvers to the ApolloClient. I’ve tried this an did not work, but also shouldn’t be necessary in the v3 version.

What I’m missing?

regards
dominix

@dominix interesting; you shouldn’t see that error message with 3.3.21. Can you share the output of running npx envinfo@latest --preset apollo --clipboard in the root of your application?

1 Like

I found the problem thanks to your help!

Because the output was that one:

  System:
    OS: Windows 10 10.0.19042
  Binaries:
    Node: 14.17.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\dev\vsm\node_modules\.bin\yarn.CMD
    npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 91.0.4472.124
    Edge: Spartan (44.19041.1023.0), Chromium (91.0.864.67)
  npmPackages:
    mock-apollo-client: ^1.1.0 => 1.1.0

So I was confused why @apollo/client is not showing in there.
I’ve looked into my yarn.lock file an found the version 3.3.21 in there (as mentioned in my initial post).
But after some more investigations I also found the old apollo-client@^2.6.10 in there.
Long story short, I’m using the nuxt module, which is using vue-apollo 3.0.4, and vue-apollo has both the old and the new apollo client as a dependency. But the old one as a peer dependency and the new one as a devDependency. Confusing stuff, but explains my issue.

So I guess I try to remove the nuxt apollo module and switch to the latest vue-apollo.

Again thanks @hwillson !

regards
dominix

1 Like

Solved.