Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
How to get that Apollo Client is refetching specific query?

There are several places in the app where specific query is refetched after different mutations.

Example:

// Some component
const [setUserLocation, setUserLocationResult] = useMutation(setUserLocationMutation, {
  refetchQueries: [{ query: getRecommendationsQuery }],
});

And in my RecommendationsComponent I want to know that this query is loading, but useQuery's loading doesn't update when getRecommendationsQuery is refetched.

const {
  data,
  loading, // this loading is false all the time except first loading
} = useQuery(getRecommendationsQuery);

I can try put useQuery's refetch to the context and use it everywhere rather than refetchQueries prop, but is there a better way to achieve that without that dirty hack - either make loading work or subscribe to that info using apollo client?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

useQuery Hook will call the api only once. You need to call the refetch function to call it again

const {
  data,
  loading, 
  refetch: getRecommendations // <- use this function to refetch the data
} = useQuery(getRecommendationsQuery);

This will also update the loading state

about 4 years ago · Juan Pablo Isaza Report

0

I got two answers in github for that question, combined them both and it finally worked:

Pass notifyOnNetworkStatusChange: true to useQuery:

const { data, loading } = useQuery(getRecommendationsQuery, {
  notifyOnNetworkStatusChange: true
});

Pass documents, not objects to refetchQueries prop:

// Some component
const [setUserLocation, setUserLocationResult] = useMutation(setUserLocationMutation, {
  refetchQueries: [getRecommendationsQuery],
});
about 4 years ago · Juan Pablo Isaza Report

0

When the query is refetched, the data will be updated. You can subscribe to changes in the data object returned from the useQuery hook:

const {
  data,
  loading,
} = useQuery(getRecommendationsQuery);

useEffect(() => {
  console.debug("data has changed!", data]);
}, [data]);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!