morrys / wora

Write Once, Render Anywhere. typescript libraries: cache-persist, apollo-offline, relay-offline, offline-first, apollo-cache, relay-store, netinfo, detect-network
https://morrys.github.io/wora/docs/introduction
MIT License
174 stars 4 forks source link

How to clear IndexedDB #62

Closed lochawala closed 3 years ago

lochawala commented 3 years ago

How can i clear IndexedDB when user logout or clear existing user data from indexDB and store new login user data?

morrys commented 3 years ago

Hi @lochawala, this should solve your problem https://www.apollographql.com/docs/react/v2.6/caching/cache-interaction/#resetting-the-store

lochawala commented 3 years ago

HI @morrys, Thanks, It's work's

lochawala commented 3 years ago

HI @morrys
I have one another question how can i clear indexDB offline store data when it's successfully sync? Please check attach screenshot for batter idea Screen Shot 2020-10-20 at 1 00 52 PM

morrys commented 3 years ago

Hi @lochawala, I didn't quite understand the question. When offline mutations are performed they are deleted from the offline store.

lochawala commented 3 years ago

Hi @morrys Yes, it's an expected behaviour but in my case, it's not deleted from an offline store

morrys commented 3 years ago

Can you give me your offline options configuration?

lochawala commented 3 years ago
client.setOfflineOptions({
    manualExecution: false, // optional
    link: link, //optional
    start: async (mutations) => { //optional
        console.log("start offline", mutations)
        return mutations;
    },
    finish: async (mutations, error) => { //optional
        console.log("finish offline", error, mutations)
    },
    onExecute: async (mutation) => { //optional
        console.log("onExecute offline", mutation)
        return mutation;
    },
    onComplete: async (options) => { //optional
        console.log("onComplete offline", options)
        onMutationCompleteHandler(client, options.response); // here in this function call client.writeQuery
    },
    onDiscard: async (options) => { //optional
        console.log("onDiscard offline", options)
        return true;
    },
    onPublish: async (offlinePayload) => { //optional
        console.log("offlinePayload", offlinePayload)
        return offlinePayload
    }
});
morrys commented 3 years ago

The problem is in onComplete function. You must return true to delete mutation in offline store :)

lochawala commented 3 years ago

Oh yes Thanks @morrys for pointing me out now it's work's