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.

refetchQueries after mutation

See original GitHub issue

Intended outcome:

I’m trying to refetch some queries after the mutation and I expect them to be executed.

Actual outcome:

refetchQueries are not working as they are described in the docs

How to reproduce the issue:

mutate({
  mutation: LOGIN_MUTATION,
  variables: {
    ...values
  },
  refetchQueries: [USER_QUERY]
})

LOGIN_MUTATION and USER_QUERY are strings in graphql syntax. I don’t see USER_QUERY gets executed after the mutation.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:51 (4 by maintainers)

github_iconTop GitHub Comments

109reactions
jbaxleyiiicommented, Jul 17, 2017

@tokenvolt I think this may be a shape issue within refetchQueries. Can you try

refetchQueries: [
{ query: USER_QUERY }
]

The object is needed in order to support things like variable changes

73reactions
n1ru4lcommented, Jul 14, 2017

From the documentation:

A list of query names which will be refetched once this mutation has

Also you will have to convert your LOGIN_MUTATION graphql strings to a GraphQL AST by using graphql-tag

It should look like this:

import gql from 'graphql-tag'

const USER_QUERY = gql`
  query currentUser {
    id
    login
  }
`

const LOGIN_MUTATION = gql`
  mutation login {
    login(login: "foobars")
  }
`
[...]

mutate({
  mutation: LOGIN_MUTATION,
  variables: {
    ...values
  },
  refetchQueries: [`currentUser`]
})


Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations in Apollo Client - Apollo GraphQL Docs
Refetching queries. If you know that your app usually needs to refetch certain queries after a particular mutation, you can include a refetchQueries...
Read more >
Refetching Queries after Mutations - Thinkster.io
We're going to cover something called "refetching" in this lesson. You can think of refetching as the equivalent of doing a GET call...
Read more >
Query refetched after a mutation doesn't trigger re-render #9270
Seeing strange behavior where useQuery hook doesn't trigger re-render when the query is included inside useMutation's refetchQueries array ...
Read more >
refetchQueries after running a mutation - Stack Overflow
Every time I run this mutation, the results of the useGetMyFavouritePlacesQuery i.e the GetMyFavouritePlacesDocument got updated automatically ( ...
Read more >
Handle item deletions in Apollo using refetchQueries
When making a mutation to delete an item in Apollo, there is no way to automatically mark ... Use the RetryLink in Apollo...
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