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

useMutation with refetchQueries, not working #6017

Closed
cristiandley opened this issue Mar 4, 2020 · 2 comments
Closed

useMutation with refetchQueries, not working #6017

cristiandley opened this issue Mar 4, 2020 · 2 comments

Comments

@cristiandley
Copy link

cristiandley commented Mar 4, 2020

Using: React.js

Im trying out refetchQueries on useMutation, i expected to have the new data to be displayed after the action occurs:

A) i populate a list with:

const {loading, error, data, refetch } = useQuery(
    GET_ALL,
    {
      fetchPolicy: 'network-only',
    }
  );

B) i execute the refetch event with some filters

refetch({
      filters,
});

C) i try to delete any element on the list:

  const [onDelete] = useMutation(DELETE, {
    refetchQueries: [{ query: GET_ALL, variables: filters }],
    awaitRefetchQueries: true,
  });

onDelete({...variables})

Whats wrong:

What actually happens is that everything occurs at network level and cache, but what is not being updated is the cache for case B (even if network displays that new data has arrived).

What do i expect:

after executing onDelete({...} my filtered list should be refreshed with the -1 entry...

Versions

System:
OS: macOS 10.15.1
Binaries:
Node: 13.5.0 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
Browsers:
Chrome: 80.0.3987.132
Firefox: 73.0.1
Safari: 13.0.3
npmPackages:
apollo-boost: ^0.4.4 => 0.4.7
apollo-cache-inmemory: ^1.2.9 => 1.6.5
apollo-client: ^2.4.1 => 2.6.8
react-apollo: ^3.0.0 => 3.1.3

@cristiandley
Copy link
Author

cristiandley commented Mar 5, 2020

My bad {filters}

const [onDelete] = useMutation(DELETE, {
    refetchQueries: [{ query: GET_ALL, variables: { filters }],
    awaitRefetchQueries: true,
  });

Should apollo be triggering an error if variables are not legible ?

@deepakbhattmits
Copy link

deepakbhattmits commented Nov 22, 2021

here is my one of Question I want to display refetchQueries data after mutation executed, how to do that ?
@cristiandley

@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

No branches or pull requests

2 participants