ember-graphql / ember-apollo-client

🚀 An ember-cli addon for Apollo Client and GraphQL
MIT License
280 stars 72 forks source link

Cache is updating but computed property is not. #384

Open SethThoburn opened 3 years ago

SethThoburn commented 3 years ago

My view fetches the needed data, including a list of comments in the model when it loads.

  @queryManager apollo;

  setupController(controller, model) {
    controller.set('approved_comments', model.commentSet.edges.filter(comment => {
      return comment.node.approved == true;
    }))
    controller.set('unapproved_comments', model.commentSet.edges.filter(comment => {
      return comment.node.approved == false;
    }))
  }

  async model(params) {
    let variables = { id: params.business_id };
    return this.apollo.watchQuery({ query, variables }, 'business')
  }

Those comments are passed to the controller on two properties which are tracked:

@tracked approved_comments;
@tracked unapproved_comments;

In that controller, an action runs a mutation which modifies some of those comments, and returns the modified comment. I see that the comment is updated in the apollo cache, but the ember tracked properties do not seem to update. The docs don't have any examples of using a watch query in a model.

christophermlne commented 3 years ago

Don't forget to request id in the return value from your mutation. Without which your cache will not update. I'm assuming that's what's happening without seeing your mutation code because I've been bitten by this several times.

On Fri., Jan. 15, 2021, 4:49 p.m. SethThoburn, notifications@github.com wrote:

My view fetches the needed data, including a list of comments in the model when it loads. `export default class MyBusinessRoute extends Route { @queryManager apollo;

setupController(controller, model) { controller.set('approved_comments', model.commentSet.edges.filter(comment => { return comment.node.approved == true; })) controller.set('unapproved_comments', model.commentSet.edges.filter(comment => { return comment.node.approved == false; })) }

async model(params) { let variables = { id: params.business_id }; return this.apollo.watchQuery({ query, variables }, 'business') } } Those comments are passed to the controller on two properties which are tracked:@Tracked https://github.com/Tracked approved_comments; @Tracked https://github.com/Tracked unapproved_comments;`

In that controller, an action runs a mutation which modifies some of those comments, and returns the modified comment. I see that the comment is updated in the apollo cache, but the ember tracked properties do not seem to update. The docs don't have any examples of using a watch query in a model.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ember-graphql/ember-apollo-client/issues/384, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHWC3O5PDNPOZP2DMNMDD3S2CZ7PANCNFSM4WEU4N2Q .

SethThoburn commented 3 years ago

I am fetching the ID, the cache updates but the UI does not.