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.

ApolloError: this.cache.batch is not a function

See original GitHub issue

Hi.

trying some auth mutation over the new released Apollo/client 3.4.1 and i have this error :


ApolloError: this.cache.batch is not a function
    at new ApolloError (/var/task/node_modules/@apollo/client/errors/errors.cjs.js:35:28)
    at Object.error (/var/task/node_modules/@apollo/client/core/core.cjs.js:1073:90)
    at notifySubscription (/var/task/node_modules/zen-observable/lib/Observable.js:140:18)
    at onNotify (/var/task/node_modules/zen-observable/lib/Observable.js:179:3)
    at SubscriptionObserver.error (/var/task/node_modules/zen-observable/lib/Observable.js:240:7)
    at /var/task/node_modules/@apollo/client/utilities/utilities.cjs.js:1015:40
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  graphQLErrors: [],
  clientErrors: [],
  networkError: TypeError: this.cache.batch is not a function
      at QueryManager.refetchQueries (/var/task/node_modules/@apollo/client/core/core.cjs.js:1601:24)
      at QueryManager.markMutationResult (/var/task/node_modules/@apollo/client/core/core.cjs.js:1136:18)
      at /var/task/node_modules/@apollo/client/core/core.cjs.js:1043:49
      at both (/var/task/node_modules/@apollo/client/utilities/utilities.cjs.js:1004:53)
      at /var/task/node_modules/@apollo/client/utilities/utilities.cjs.js:997:72
      at new Promise (<anonymous>)
      at Object.then (/var/task/node_modules/@apollo/client/utilities/utilities.cjs.js:997:24)
      at Object.next (/var/task/node_modules/@apollo/client/utilities/utilities.cjs.js:1005:49)
      at notifySubscription (/var/task/node_modules/zen-observable/lib/Observable.js:135:18)
      at onNotify (/var/task/node_modules/zen-observable/lib/Observable.js:179:3),
  extraInfo: undefined
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
benjamncommented, Aug 3, 2021

@carelulu-igor Thank you for including your imports, especially the import of InMemoryCache.

The reason this code is not using the latest implementation of InMemoryCache is that it’s still importing InMemoryCache from the AC2 apollo-cache-inmemory npm package (last published more than a year ago!). You can/should import InMemoryCache from @apollo/client instead now. The older package still exists for folks also using the older apollo-client package, but you definitely should not be mixing @apollo/client and apollo-cache-inmemory together.

The good news: you’re about to experience a ton of improvements to InMemoryCache all at once!

The realistic news: some of those changes will be breaking. For example, the IntrospectionFragmentMatcher no longer exists. Fortunately, the new way of providing possibleTypes is much simpler:

const memoryCache = new InMemoryCache({
  possibleTypes: {
    xyz: ["abc", "def"],
  },
}).restore(cache);

While you’re at it, I would also suggest you stop using apollo-link-http and import createHttpLink this way instead:

import { createHttpLink } from "@apollo/client/link/http"

These won’t be the only changes you’ll have to contend with as you update, but I hope you’ll find the InMemoryCache-related parts of the AC3 migration guide useful.

@mfurniss Does this explanation of @carelulu-igor’s problem explain what’s up in your case? I can’t really tell if they’re the same problem from the code you provided above.

6reactions
foxcode-designscommented, Aug 2, 2021

I have the same error on our dev server with both 3.3.21 as 3.4.1. Locally everything runs fine but on the dev server when I execute the mutation, it goes straight after in the catch function (even though I get a 200 response with correct data) and outputs ‘this.cache.batch is not a function’. I’m using default InMemoryCache which I cleared too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ApolloError: this.cache.batch is not a function - Stack Overflow
This issue is related to the deprecated cacher class. If you are using some cacher class just make sure it's up to date....
Read more >
Advanced topics on caching in Apollo Client
This article describes special cases and considerations when using the Apollo Client cache. Bypassing the cache. Sometimes you shouldn't use the cache for...
Read more >
this.cache.batch is not a function - Zenn
trying some auth mutation over Apollo/client 3.4.1 and i have this error : ApolloError: this.cache. stackoverflow.com favicon image ...
Read more >
apollo-cache-inmemory - Awesome JS
IMPORTANT Version 3.7.3 is not installable due to an issue with our ... Make cache.batch return the result of calling the options.update function....
Read more >
Customizing the behavior of cached fields - Client (React)
The following read function assigns a default value of UNKNOWN NAME to the name field of a Person type, if the actual value...
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