Triggering one query is triggering other related ones

Triggering one query is triggering other related ones


0

I suppose its because of cache? But i have Query01 that i trigger using a button click, and Query02 that had run previously, when Query01 runs, it reruns query 02. What is going on??

Here’s the structures:

  query Query01(
    $patientId: Something!
    $externalId: String
    $externalEncounterId: String!
  ) {
    patient(patientId: $patientId) {
      pastMedicalHistory {}
      prescriptions {}
    }
}
  query Query02(
    $patientId: Something!
    $externalEncounterId: String!
  ) {
    patient(patientId: $patientId) {
      prescriptions(externalEncounterId: $externalEncounterId) {
        list {
          displayLabel
        }
      }
    }
  }
`;

How i call query 1 and 2 are the same way:

const [retrievePatientPrescriptions, { loading: isLoading }] = useLazyQuery<
    PrescriptionsGraphQLDisplayLabelReturn,
    PatientPrescriptionsVariables
  >(PatientPrescriptionsDisplayLabels, { fetchPolicy: 'network-only' });


<button onClick={() => retrievePatientPrescriptions(...)}></button>

The only difference is that query2 is called using query instead:

const {
    loading: isLoading,
    data,
    error,
  } = useQuery<PatientWithHistoriesSectionsGraphQLResult, GetPatientParams>(
    PatientWithClinicalSections,
    {
      variables: {
....
      },
      fetchPolicy: 'network-only',    }
  );

6

  • You'll need to show your react code where these queries are run. One gql query will not generally force another one to run (there are some exceptions for example with mutations where you can specify a set of queries to re-run after the mutation succeeds).

    – Michel Floyd

    1 hour ago

  • updated @MichelFloyd

    – PlayMa256

    1 hour ago

  • How are your react components nested? Does an update to one cause the other to re-render? If so that would trigger a re-run of the other query.

    – Michel Floyd

    54 mins ago

  • Also both queries use the same patientId variable – is that changing?

    – Michel Floyd

    38 mins ago

  • yes both queries use the same patientId, actually the problem here is more of a cache rather than rerendering of reacrt components, but im not really sure how to make those two queries idempotent.

    – PlayMa256

    24 mins ago


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *