question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setVariables doesn't notify subscribers when cache hit

See original GitHub issue

Intended 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:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
s-panferovcommented, Dec 21, 2017

The same for refetch, it does not call .next() too

1reaction
PowerKiKicommented, Jul 28, 2018

Migrated to https://github.com/apollographql/apollo-feature-requests/issues/25, because the current situation is confusing at best or buggy at worst.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found