Apollo-client: cache.modify() not a function

Created on 28 Apr 2020  路  9Comments  路  Source: apollographql/apollo-client

Hello,

I have a problem with cache.modify() when trying to update the cache in a resolver with the v.3.0 beta @apollo/client version.

The chrome browser tells me that modify() is not a function:
cache.identify is working.
image

Here is my code :
`export const resolvers: any = {

Mutation: {
updateApplicationProofUrl: (__:any, {input}:any, {cache, getCacheKey}:any) => {
const {jobId, signedGetUrl} = input
const id = cache.identify({
__typename: 'Job',
id: jobId
})
console.log('id', id)
cache.modify(id, {applicationProofUrl: signedGetUrl})
}
},
}`
Note : cache.identify() is working.

My cache is configured with this
// Graphql default state const cache = new InMemoryCache(); const link = new HttpLink({ uri: "http://localhost:5001" }) // GraphqlClient const client = new ApolloClient<NormalizedCacheObject>({ link, cache, typeDefs, resolvers, connectToDevTools: true })

Do you have an idea of the problem ?

It's my first ever issue posting on any library so if it misses some info, don't hesitate to tell me.

Thank you for your help !

Most helpful comment

Please note that https://www.apollographql.com/docs/react/data/mutations/ still refers to cache.modify in its examples

All 9 comments

@philvc cache.modify was recently removed. See https://github.com/apollographql/apollo-client/pull/6289 for the full details.

Please note that https://www.apollographql.com/docs/react/data/mutations/ still refers to cache.modify in its examples

For the record, we reinstated cache.modify in #6350, after outcry over #6289.

I'm getting this error on the latest @apollo/client: 3.2.5

I'm seeing it in 3.3.0-rc2 also:

index.js:1 Error: modify is not a function
    at new ApolloError (index.js:26)
    at Object.next (QueryManager.js:110)
    at notifySubscription (Observable.js:135)
    at onNotify (Observable.js:179)
    at SubscriptionObserver.next (Observable.js:235)
    at iteration.js:4
    at Array.forEach (<anonymous>)
    at iterateObserversSafely (iteration.js:4)
    at Object.next (Concast.js:24)
    at notifySubscription (Observable.js:135)
    at onNotify (Observable.js:179)
    at SubscriptionObserver.next (Observable.js:235)
    at Object.next (index.js:29)
    at notifySubscription (Observable.js:135)
    at onNotify (Observable.js:179)
    at SubscriptionObserver.next (Observable.js:235)
    at createHttpLink.js:100

Aye I'm seeing this in 3.2.7. I'm reasonably new to Apollo and while lots of the docs are great, I' just so confused about how cache updates are meant to be done without refetchQueries. 馃く

Seeing the error as well in "@apollo/client": "^3.3.7"

I was having this problem because I had accidentally installed apollo-client instead of @apollo/client .

Was this page helpful?
0 / 5 - 0 ratings