简体   繁体   中英

How to refetch an Apollo GraphQL query with InMemoryCache and without changing the fetch policy?

I have a project set up with ApolloClient & InMemoryCache. It works, in general. In one component I fetch some data and want to have a button to refetch it.

const userQuery = useQuery<GetAllUsers>(GET_USER_QUERY, {
  // fetchPolicy: 'cache-and-network',
})

// in the button event handler
console.log(await userQuery.refetch(())

This logs undefined and causes no network request.

If I change the fetchPolicy the refetch starts to work, but with an array of negative consequences.

Is there any way to get refetch to actually refetch despite the cache without changing the fetch policy?

I have a project set up with ApolloClient & InMemoryCache. It works, in general. In one component I fetch some data and want to have a button to refetch it.

const userQuery = useQuery<GetAllUsers>(GET_USER_QUERY, {
  // fetchPolicy: 'cache-and-network',
})

// in the button event handler
console.log(await userQuery.refetch(())

This logs undefined and causes no network request.

If I change the fetchPolicy the refetch starts to work, but with an array of negative consequences.

Is there any way to get refetch to actually refetch despite the cache without changing the fetch policy?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM