Skip to content
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

RefetchQueries will only refetch the first query that is called when 2 with same name. #4115

Closed
happylinks opened this issue Nov 8, 2018 · 3 comments
Labels
🚧 in-triage Issue currently being triaged

Comments

@happylinks
Copy link
Contributor

When there's two active queries in Apollo with the same name, refetchQueries will only refetch the first query that is called.

Intended outcome:
RefetchQueries always refetches the last query when there are more with the same name, not the first.

Actual outcome:
RefetchQueries always refetches the first query called when there are multiple with the same name.

How to reproduce the issue:
image

https://github.com/happylinks/react-apollo-error-template

I had an issue with publishing it to gh-pages ("Failed to get remote.https://github.com/happylinks/react-apollo-error-template.git.url (task must either be run in a git repository with a configured https://github.com/happylinks/react-apollo-error-template.git remote or must be configured with the "repo" option).
")

Versions

System:
OS: macOS 10.14.1
Binaries:
Node: 10.9.0 - ~/.nvm/versions/node/v10.9.0/bin/node
Yarn: 1.9.4 - ~/.nvm/versions/node/v10.9.0/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.9.0/bin/npm
Browsers:
Chrome: 70.0.3538.77
Firefox: 63.0.1
Safari: 12.0.1
npmPackages:
apollo-cache-inmemory: ^1.2.2 => 1.2.2
apollo-client: ^2.3.2 => 2.3.2
apollo-link: ^1.2.2 => 1.2.2
apollo-link-schema: ^1.1.1 => 1.1.1
react-apollo: 2.1.4 => 2.1.4
npmGlobalPackages:
apollo: 1.9.1

@happylinks
Copy link
Contributor Author

Digging a bit into the code I found this:

private refetchQueryByName(queryName: string) {
const refetchedQueries = this.queryIdsByName[queryName];
// early return if the query named does not exist (not yet fetched)
// this used to warn but it may be inteneded behavoir to try and refetch
// un called queries because they could be on different routes
if (refetchedQueries === undefined) return;
return Promise.all(
refetchedQueries
.map(id => this.getQuery(id).observableQuery)
.filter(x => !!x)
.map((x: ObservableQuery<any>) => x.refetch()),
);
}

So it seems that it should refetch all the queries, eventhough they have the same name. This is not what I see happening in my app though 🤔

@pl12133
Copy link

pl12133 commented Nov 9, 2018

This is a great detailed write up, I think you are facing #3540.

@hwillson hwillson added the 🚧 in-triage Issue currently being triaged label Jul 9, 2019
@hwillson
Copy link
Member

hwillson commented Jul 9, 2019

Duplicate of #3540.

@hwillson hwillson closed this as completed Jul 9, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🚧 in-triage Issue currently being triaged
Projects
None yet
Development

No branches or pull requests

3 participants