setVariables doesn't notify subscribers when cache hit
See original GitHub issueIntended outcome:
Calling setVariables()
on a ObservableQuery
should notify subscribers of a data change. This works as expected if the query is not cached and results in a network request.
Actual outcome:
If a query has been cached setVariables()
does not notify its subscribers of the data change. From tracing the code it appears the correct data is pulled from the cache and set as the query result, however subscribers are never notified of the result like they are when a network query occurs.
How to reproduce the issue:
app.module.ts
constructor(apollo: Apollo, httpLink: HttpLink) {
apollo.create({
link: httpLink.create({}),
cache: new InMemoryCache()
});
}
data.service.ts
const TestQuery = gql`
query TestQuery($name: String!) {
users(name: $name) {
name
userid
}
}
`;
constructor(private apollo: Apollo) {
this.queryRef = this.apollo.watchQuery<QueryResponse>({
query: TestQuery,
variables: {
name: ""
}
});
}
getUsers() {
return this.queryRef.valueChanges;
}
nameUpdate(name) {
this.queryRef.setVariables({
name: name
});
}
view.component.ts
ngOnInit() {
this.dataService.getUsers().subscribe({data}) => {
this.users = data.users;
});
}
// These are tied to user actions, but for demonstrating the issue, calling directly.
this.dataService.nameUpdate('bob'); // Performs new network query and updates observable
this.dataService.nameUpdate('john'); // Performs new network query and updates observable
this.dataService.nameUpdate('bob'); // Queries the cache and DOES NOT update observable
Versions
- apollo-client@2.1.0
- apollo-cache@1.0.2
- apollo-cache-inmemory@1.1.3
- apollo-angular@1.0.0
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Fix subscriber notification problems - YouTube Help
When uploading a video, keep the box next to “Publish to Subscriptions feed and notify subscribers” on the “Advanced settings” tab checked. Check...
Read more >3 Known Issues and Workarounds - Oracle Help Center
The cache hit and miss counts may rise unexpectedly when manipulating entities without version data. The extra cache access occurs when the EntityManager ......
Read more >Activiti User Guide
Deployment cache configuration. All process definition are cached (after they're parsed) to avoid hitting the database every time a process definition is needed ......
Read more >FCM does not deliver notification to all the topic subscribers ...
It's a data notification, so there is no problem with the background / foreground / not started state of the app. In the...
Read more >Notification Set Variables - the Mimecast Community
Notification Sets are used to notify end users why an email / attachment has not been delivered, or about messages that are pending...
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 FreeTop 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
Top GitHub Comments
The same for
refetch
, it does not call.next()
tooMigrated to https://github.com/apollographql/apollo-feature-requests/issues/25, because the current situation is confusing at best or buggy at worst.