Open alexwine36 opened 7 years ago
I also recently had this issue and thought I would leave my solution. This seems to be more related to Apollo. Adding fetchPolicy: "network-only"
after variables will force the request to happen. Docs here
What I concluded is the way Apollo caches data, it automatically uses cached data and bypasses a request if a document with the same id
or _id
(by default) already exists in the cache. Even if the rest of the data has changed. Changing the fetch policy will change this behavior.
I'm assuming this is your problem as well and not the typo vaiables
in your code.
I am having the same issues, and even as I am using fetchPolicy: "network-only" or I even tried fetchPolicy: "no-cache". I can't get the query to re-run even though an edit mutation has been done on the same document.
Template.patientInfo.created = function() {
this.member = new ReactiveVar(false);
Session.set("showLoadingPatientForm", false);
tempInst = this;
this.autorun(function() {
if (Session.get("showLoadingPatientForm")) console.log("reload");
if (FlowRouter.getParam("id")) {
let variables = { _id: FlowRouter.getParam("id") };
let currentPatient = Template.instance()
.gqlQuery({
query: GET_PATIENT,
fetchPolicy: "no-cache",
variables: variables
})
.get();
if (currentPatient && currentPatient.patient) {
tempInst.member.set(currentPatient.patient);
Session.set("showLoadingPatientForm", false);
}
} else {
tempInst.member.set({});
}
});
};
I am checking in the DB and the object has chanegd but the GET_PATIENT query is not run because I have logs there.
I think the issue is that Blaze Apollo does it's own (kind-of) caching to prevent unneeded reruns in autoruns (like template helpers).
If the request doesn't change (like when it has network-only
the first and second time) I think the result will also not change.
I don't know yet how to fix this. If we don't use the Blaze caching then you can't directly use the queries in helpers, but need to define them in the onCreated and pass it to a ReactiveVar which you'll use in your helpers, for example. That's a lot less fluent, but safer.
Any other suggestions are welcome.
Side note: As you might have noticed, Blaze-Apollo isn't actively maintained/developed, because we're moving to React ourselves. Blaze is great, but has a lot of quirks. We have more trust in React for future development and projects. If we can fix things with reasonable investment, we will, but Blaze-Apollo will stay mostly "as is". Thanks.
@boboci9, re-reading your issue it seems that nothing will trigger your autorun so no attempt will be made to do a refetch. If a mutation was done somewhere, make sure you update the Apollo cache correctly. That should trigger the underlying watchQuery. Changing the FlowRouter id param starts a new query, right?
I am trying to run a new query on the client and for the life of me I can not get not bypass the cached results This is the code that I am running and changing the variables that are being used seems to have no effect on the result that is returned
Any help would be greatly appreciated currently I am at the banging my head on a wall stage...