Swydo / blaze-apollo

Blaze integration for the Apollo Client
MIT License
54 stars 6 forks source link

How to use gqlSubscribe #17

Open boboci9 opened 5 years ago

boboci9 commented 5 years ago

Hi,

I am trying to get a refetch of the data that has been changed by a mutation but I can't get the query to rerun. If I call the gqlSubscribe with the same query and variables I see the logs from the query reaching the new data but the gqlQuery is not rerun. I couldn't find it in the docs how could I use the gqlSubscribe in a situation like this

Template.patientInfo.created = function() {
  this.member = new ReactiveVar(false);
  Session.set("showLoadingPatientForm", false);

  tempInst = this;
  this.autorun(function() {
    console.log(Session.get("showLoadingPatientForm"));
    if (Session.get("showLoadingPatientForm")) console.log("reload");
    if (FlowRouter.getParam("id")) {
      let variables = { _id: FlowRouter.getParam("id") };

      console.log("subs",
        Template.instance()
          .gqlSubscribe({
            query: GET_PATIENT,
            variables: variables
          })); // here I can see the query logs reach the new data but the gqlQuery won't run again
      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({});
    }
  });
};