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

[3.0 beta-43]: reFetchObservableQueries causes skipped query to be fetched #6154

Closed
dhalbrook opened this issue Apr 16, 2020 · 5 comments · Fixed by #7146
Closed

[3.0 beta-43]: reFetchObservableQueries causes skipped query to be fetched #6154

dhalbrook opened this issue Apr 16, 2020 · 5 comments · Fixed by #7146

Comments

@dhalbrook
Copy link

dhalbrook commented Apr 16, 2020

We have some logic that checks which workspace a user is when navigating through our app:

  const nodeId = UrlHelper.getNodeIdFromUrl(router);

  const { data: nodeData, error: nodeError, loading: nodeLoading } = useQuery<
    CurrentNodeQuery,
    CurrentNodeQueryVariables
  >(currentNodeQuery, {
    skip: !nodeId,
    variables: {
      id: IdConverter.encodeId(nodeId)
    },
    errorPolicy: 'all'
  });

If no workspace can be found, it's skipped.

If the user is anonymous and navigates elsewhere and decides to login, we clear the cache and refetch queries:

      await client.clearStore();
     ... other stuff...
      await client.reFetchObservableQueries(false);

Doing this re-executes the query to check the workspace. However, at that point the "skip" logic is ignored and the query fails because there is no workspace in the context, causing the workspace ID to be null. Therefore we get the following error:

"[GraphQL error]: Message: Field 'id' of variable 'id' has coerced Null value for NonNull type 'ID!', Location: [{"line":1,"column":19}], Path: undefined

Intended outcome:
Ideally only non-skipped queries would be re-executed, or the skip logic would be re-run somehow (a callback function for "skip" perhaps ?). This doesn't seem to be happening.

*Actual outcome:

"reFetchObservableQueries" is refetching all queries, regardless of whether they should be skipped or not.

How to reproduce the issue:

I'm working on some reproduction code.

Versions

System:
OS: macOS 10.15.4
Binaries:
Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node
Yarn: 1.22.0 - ~/.nvm/versions/node/v12.14.1/bin/yarn
npm: 6.13.4 - ~/.nvm/versions/node/v12.14.1/bin/npm
Browsers:
Chrome: 81.0.4044.92
Firefox: 75.0
Safari: 13.1
npmPackages:
@apollo/client: ^3.0.0-beta.43 => 3.0.0-beta.43
@apollo/link-batch-http: ^2.0.0-beta.3 => 2.0.0-beta.3
@apollo/link-context: ^2.0.0-beta.3 => 2.0.0-beta.3
@apollo/link-error: ^2.0.0-beta.3 => 2.0.0-beta.3
@apollo/react-common: ^4.0.0-beta.1 => 4.0.0-beta.1
@apollo/react-components: ^4.0.0-beta.1 => 4.0.0-beta.1
@apollo/react-hoc: ^4.0.0-beta.1 => 4.0.0-beta.1
@apollo/react-ssr: ^4.0.0-beta.1 => 4.0.0-beta.1
apollo-link-log: ^1.1.3 => 1.1.3
apollo-server: ^2.11.0 => 2.11.0
react-apollo: ^3.1.3 => 3.1.3

@dhalbrook dhalbrook changed the title reFetchObservableQueries causes skipped query to be fetched [3.0 beta-43]: reFetchObservableQueries causes skipped query to be fetched Apr 16, 2020
@zzh8829
Copy link

zzh8829 commented Jun 11, 2020

This is affecting me as well, I arrived at the same conclusion as op, reFetchObservableQueries is not respecting the skip options.

The official guide here recommends calling client.resetStore() on user logout, but it will unintentionally cause all skipped query to fire due to this bug.

possibly related issues:
#6342
#6190
apollographql/react-apollo#3492

@buzinas
Copy link

buzinas commented Jun 16, 2020

Yep, broken. See apollographql/react-apollo#3492 (comment).

@joncursi
Copy link

joncursi commented Oct 7, 2020

I noticed that client.resetStore() is also executing skipped queries, which is very problematic. See: #7113

@joshjg
Copy link
Contributor

joshjg commented Oct 9, 2020

Appears to have been caused by #6999 which was intended to fix #6796

What I don't understand is the use case/motivation behind #6796 in the first place. Why would you want to refetch a skipped query? If it's a workaround due to the mentioned useLazyQyery limitation, it seems wrong to accommodate that via useQuery.

@benjamn
Copy link
Member

benjamn commented Oct 13, 2020

This should be fixed in @apollo/client@3.2.4, thanks to #7146 by @joshjg.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants