Subscription updateQuery triggers refetch
See original GitHub issueIntended outcome:
When receiving data from a websocket subscription, only the original useQuery
data
object should get modified.
Actual outcome:
When receiving data from a websocket subscription, the original query as defined in useQuery
is run again as if refetch
was called.
This happens each time new subscription data is received.
How to reproduce the issue:
The issue occurs with this simple setup:
const MyComponent = () => {
const { subscribeToMore } = useQuery(MY_QUERY, {
fetchPolicy: 'cache-and-network',
})
useEffect(() => {
return subscribeToMore({
document: MY_SUBSCRIPTION,
updateQuery: (prev, { subscriptionData }) => {
return subscriptionData.data
},
})
}, [])
return null
}
MY_QUERY
and MY_SUBSCRIPTION
are identical (except for the query
and subscription
prefix) and include an id
for all types.
Versions
System:
OS: Linux 4.15 Ubuntu 18.04.4 LTS (Bionic Beaver)
Binaries:
Node: 12.16.2 - ~/.nvm/versions/node/v12.16.2/bin/node
npm: 6.14.4 - ~/.nvm/versions/node/v12.16.2/bin/npm
Browsers:
Chrome: 83.0.4103.61
Firefox: 76.0.1
npmPackages:
@apollo/client: ^3.0.0-beta.50 => 3.0.0-beta.50
@apollo/link-ws: ^2.0.0-beta.3 => 2.0.0-beta.3
This behavior seems to have been introduced in 3.0.0-beta.46
.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Refetching queries in Apollo Client - Apollo GraphQL Docs
Refetch options ; updateCache. (cache: TCache) => void. Optional function that updates cached fields to trigger refetches of queries that include those fields....
Read more >How to refetch a query when a new subscription arrives in ...
I was wondering if there's an elegant way to trigger the refetch of a query in react-apollo when a subscription receives new data...
Read more >Subscriptions | Vue Apollo
GraphQL subscriptions are a way to push data from the server to the ... In most cases, intermittent polling or manual refetching are...
Read more >Subscriptions - Client (React) - Apollo GraphQL Docs
Like queries, subscriptions enable you to fetch data. ... updateQuery is a function that tells Apollo Client how to combine the query's currently...
Read more >Update query in a trigger - mysql - DBA Stack Exchange
I am using dynamic SQL. This works fine inside the procedure. Problem is: I want to fetch the current date values into the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m pretty sure the same thing is causing
fetchMore
not to work either. If you have afetchPolicy
that does network fetches, the data is refetched, overwriting your updated data.E.g. something like this:
I suspect this issue has the same cause as #6327 and #6305, which have runnable examples.