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).
1 hour ago
updated @MichelFloyd
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.
54 mins ago
Also both queries use the same
patientId
variable – is that changing?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.
24 mins ago