I was unable to find anything in the docs, tutorials, or example projects about how to exactly use watch queries in data-loading components. From the docs, I know that I can use the ComponentQueryManager which will track active watch queries and unsubscribe when the component is destroyed. I also know that watchQuery will return an Ember.Object and can be used in computed properties. What I don't know is how an actual implementation looks. Based on the above information, I would assume that the following works but it does not.
import Component from '@ember/component'
import { computed } from '@ember/object'
import { inject as service } from '@ember/service'
import { ComponentQueryManager } from 'ember-apollo-client'
import query from 'tbui/gql/queries/pets'
export default class SideBar extends Component.extend(ComponentQueryManager) {
async didInsertElement() {
let variables = { ownerId: '1' }
let result = await this.apollo.watchQuery(
{
query,
variables,
},
'pets'
)
this.set('activeQuery', result)
}
@computed('activeQuery')
get numberOfPets() {
console.log('query updated')
return this.activeQuery ? this.activeQuery.length : null
}
}
The computed property never gets updated even though it is utilized in the template.
I was unable to find anything in the docs, tutorials, or example projects about how to exactly use watch queries in data-loading components. From the docs, I know that I can use the
ComponentQueryManagerwhich will track active watch queries and unsubscribe when the component is destroyed. I also know thatwatchQuerywill return anEmber.Objectand can be used in computed properties. What I don't know is how an actual implementation looks. Based on the above information, I would assume that the following works but it does not.The computed property never gets updated even though it is utilized in the template.