-
Notifications
You must be signed in to change notification settings - Fork 100
defaultOptions with fetchPolicy: 'cache-and-network' causes local states to be overwritten with defaults #236
Comments
Btw. the way I solved it for now is to manually set any query with a "@client" directive in it to use
I haven't checked this with any mixed client/network queries yet though... |
Even I am facing similar issue where default data is being returned instead of actual updated data from cache. Any updates on this? |
Hi @isopterix, can you please provide a stripped down reproduction in CodeSandbox so I can look into this? Thanks! |
Hi @peggyrayzis, will try to put something together shortly. |
I have the same problem even with setting |
I tried to put something together... but for whatever reason I am getting "Cannot read property 'Query' of undefined" in the console... |
Any updates on this? I had to remove defaults as work-around for this issue. |
Also experiencing this issue. With a mixed client/network query, the issue seems to still occur even when using |
I'm seeing the same issue. Defaults overwrite the persisted cache when a global config of |
Hi, Is there a temporary fix or work-around for this? |
I’m experiencing a similar issue. I’m using next.js and cache is being filled on a server side, dumped to var, which is passed to the browser and used for rehydration during cache initialization on the browser side. Problem occurs when I’m trying to query cache after - it contains only defaults from apollo-link-state. It looks like setting defaults doesn’t care if there is something in the cache already. |
Same for me :( |
Related: #262 |
I've got same issue, and fixed it by removing the defaults from withClientState(), and writing them directly in the apollo cache. Here is my code:
|
Same problem here. I've broken it down to 2 separate issues:
|
Oh BTW this guy seems to have found a workaround for not overwriting with defaults: awslabs/aws-mobile-appsync-sdk-js#195 (comment) |
apollo-link-state is in the process of being integrated into apollo-client, including multiple bug fixes and new features. For more info, see apollographql/apollo-client#4338. You can try it out by installing I'm not personally involved in the development and haven't tested to see if it fixes this bug, but my understanding is that it should be fixed by the time apollo-client 2.5 is released. Note that the API is still subject to change. |
Anyone who can explain why |
Guys, I'm having very similar issues. Have a good look at your indexing logic. Any null keys are not cached. Worse: non-unique keys tend to be overwritten. Make sure this only happens when you want it to. |
Apollo 2.5 has been released. I doubt there will be any further changes to this library now that local state has been integrated into the core. |
@peggyrayzis could we move this to the apollo repository? |
Hi,
I ran into an issue when setting the global fetchPolicy setting for query and watchQuery to cache-and-network while using apollo-link-state and apollo-cache-persist.
My defaultOptions in my Apollo configuration look like this:
For whatever reason I cannot get Apollo to grab the persistent cache from the browser and use the client state flag to assess whether a user is logged in or not.
When I set the queries' fetchPolicy manually to cache-and-network without defining it globally via the defaultOptions tag in the Apollo configuration everything works fine. However, if I use the same approach to fetch the local state via the "@client" directive, the local state read from the cache is somehow overwritte with the default when the network re-fetch is initiated shortly after the cache is initially read. Hence, the user always sees the login screen as the appUserIsLoggedin setting is always reset to false.
Below are my two config files. Note that in this version the defaultOptions are commented out and hence the Q_GET_APP_LOGIN_STATE query in the index file is fetched standard cache-first method. THIS WORKS AS EXPECTED!
However, if I activate the defaultOptions setting OR manually set fetchPolicy for the Q_GET_APP_LOGIN_STATE query to cache-and-network, the appUserIsLoggedin variable is initially true when loading the page and a cache with it set to true is present. However, shortly after, the local-state variable is automatically set to false again for whatever reason. I assume this is the result of the automated network re-fetch.
PLEASE NOTE: This ONLY affects data which is stored in the local-state. Data fetched from the network works as expected regardless of the used fetchPolicy setting.
Any ideas what may be the cause for this?
My React Index file:
My Apollo configuration:
My package versions:
The text was updated successfully, but these errors were encountered: