0

I'm trying to use refetchQueries to get an updated list of record after a mutation. I have tried below code to get updated data but the updated data showing in network tab of the developer console.

This is for reactjs 16.8 and "react-apollo": "^2.5.5" and it seems awaitRefetchQueries: true not working

client.mutate({
        mutation: ADD_ACTIVE_CREW,
        variables: {
          activeCrewInfo: {
            employee: activeCrew[0].vp_id,
            date_on_crew: new Date(),
            crew_id: selectedCrewId
          }
        },
        options: () => ({
          refetchQueries: [
            {
              query: GET_EMPLOYEE_BY_CREW_ID_QUERY,
              variables: { crew_id: crew_id }
            }
          ]
        }),
        awaitRefetchQueries: true

      });

I'm getting correct response in developer console's network tab, but not able to access in my reactjs application.

  • `.then(() => this.setState(whatever))` – Joseph D. Aug 08 '19 at 05:31
  • ` .then(result => { const arrUpdatedData = result.data; console.log(arrUpdatedData); }) .catch(err => console.log(err)); ` I have checked with the above code but it not getting correct data. – Ramesh Kumar Aug 08 '19 at 05:45

1 Answers1

0

The mutation data itself will never reflect the refetched queries.

Any queries you tell Apollo to refetch will be requested and then have their result written to the cache. That means any Query components or components using useQuery or watchQuery will be updated, provided the query and variables parameters match what's in refetchQueries.

If you don't already have a component that uses that query, you need to add one.

Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183