josemarluedke / glimmer-apollo

Ember and Glimmer integration for Apollo Client.
https://glimmer-apollo.com
MIT License
38 stars 14 forks source link

Query's loading and networkStatus properties don't appear to update after initial fetch #60

Closed billdami closed 2 years ago

billdami commented 2 years ago

I have a useQuery() instance in a component (Ember app, with Glimmer components), and attempting to update the template to show a spinner when the query is "refetching" after the initial render/query request completes. However, it does not appear that the loading or networkStatus values change when a new request is fired via refetch(). For example, I'm trying to do the following:

query = useQuery(this, () => [MY_QUERY, { fetchPolicy: 'network-only' }]),

// => this is always false
get isRefetching() {
     return this.query.networkStatus === NetworkStatus.refetch;
}

@action
reload() {
     this.query.refetch();
     // = > this always prints false for `loading` and `7` ("ready") for networkStatus
     // would expect at least networkStatus to be `4` ("refetch") here
     console.log(this.query.loading, this.query.networkStatus);
}
{{#if this.isRefetching}}
    loading...
    {{! this never shows after calling reload() }}
{{else}}
     {{! .... }}
{{/if}}
billdami commented 2 years ago

@josemarluedke is the behavior I'm expecting here jive with what the library actually should be doing? This is only real issue barring my team from being able to use glimmer-apollo in our apps.

I've tried initializing queries in different contexts (on a controller, in a component, etc), and also @tracking the query property, but didnt seem to make any difference.

I'm not to familiar with the Observable logic, but that should be triggering template-aware state changes when loading and networkStatus change internally right? Or does this indicate that those updates only trigger when query requests are actually finished? https://github.com/josemarluedke/glimmer-apollo/blob/main/packages/glimmer-apollo/src/-private/query.ts#L130

billdami commented 2 years ago

Ignore this! Totally missed the bit in the docs about having to enable notifyOnNetworkStatusChange 🤦 I just assumed that would be the default behavior.