-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apollo Client 3 - optimistic response with pollInterval doesnt work. #6858
Comments
Can you try |
Just tried it, and it looks to be the same issue. However, it looks like if I bump the polling to 30 seconds from 3 seconds, it works as expected until its first poll response comes back. |
@andymrussell Ok, I have a slightly stronger hunch that |
@benjamn this is still broken in v3.3.13 |
btw, tried 3.4.0-beta.19 and it's broken too |
Same for me. For now. I am considering setting up a graphql subscription to handle it. Edit: I solved this by not having an initial pollInterval and instead controlling it with startPolling and stopPolling. I had the problem appear when the app lost connection as I relied on optimisticResponse and cache.modify in the update function for offline functionality.
|
@andrujoh good work around, I ended up going for subscriptions. |
Thanks for reporting! I attempted to reproduce the issue here but could not replicate the issue you were describing. I am probably misunderstanding the exact way your queries and mutations are set up. If you can try and create a runnable reproduction, I’ll take another look! |
Might be related to #7115 |
I had the same issue, but updating from As described above, optimistic updates worked until the first polling happened. Afterwards, the cache would only update with the server response of the mutation. |
Thanks for the update, @m-lautenbach! I'm going to close this issue in that case, but if anyone can provide a runnable reproduction with |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Intended outcome:
When using optimisticResponse or using cache.writeQuery as part of a mutation, components using pollInterval don't seem to update until the payload from the mutation has been successful.
I have 2 components using the same data. 1 is polling, the other fetches the data from the cache - network.
The non polling component updates correctly, however the polling component waits from the response to come back from the API before updating.
Actual outcome:
Once, the response comes back from the server the polling component updates.
How to reproduce the issue:
Query some data using a hook:
const { data, refetch } = useGetChannelByIdQuery({ skip: !activeChannel, variables: { id: activeChannelId! }, fetchPolicy: 'cache-and-network', pollInterval: 3000, });
Create a mutation and set an optimistic response:
const onFavoriteChannel = (isFavorite: boolean) => { onFavoriteChannelMutation({ variables: { input: { id: props.channel.id, isFavorite } }, optimisticResponse: { __typename: 'Mutation', favoriteChannel: { id: props.channel.id, name: props.channel.name, isFavorite, __typename: 'Channel', }, }, }); };
OR anything with proxy.writeQuery:
Remove the pollInterval from the query, to confirm it works.
Versions
System:
OS: macOS Mojave 10.14
Binaries:
Node: 12.18.3 - ~/.nvm/versions/node/v12.18.3/bin/node
npm: 6.14.6 - ~/.nvm/versions/node/v12.18.3/bin/npm
Browsers:
Chrome: 84.0.4147.125
Firefox: 28.0
Safari: 12.0
npmPackages:
@apollo/client: ^3.1.3 => 3.1.3
The text was updated successfully, but these errors were encountered: