Skip to content

Waiter not registered for some async calls #192

Description

@viniciussbs

When we face this issue:

There are some scenarios when settled does not wait for some async calls:

  • when there is a watched query and we refetch the query;
  • when there is a watched query and we fetch more data;
  • when we send a mutation with the option refetchQueries;

We just increment the ongoing counter for the first fetch. When we call refetch, fetchMore or set refetchQueries when sending a mutation, we do not register those ongoing requests.

How this is solved in my app

Query Manager

import QueryManager from 'ember-apollo-client/apollo/query-manager';

export default QueryManager.extend({
  refetch(opts, observable) {
    return this.apollo.refetch(opts, observable);
  },

  fetchMore(opts, observable) {
    return this.apollo.fetchMore(opts, observable);
  }
});

Service

import ApolloService from 'ember-apollo-client/services/apollo';
import QueryManager from 'my-app/apollo/query-manager';

export default ApolloService.extend({
  createQueryManager() {
    return QueryManager.create({ apollo: this });
  },

  refetch(opts, observable) {
    return this._waitFor(observable.refetch(opts));
  },

  fetchMore(opts, observable) {
    return this._waitFor(observable.fetchMore(opts));
  },

  mutate(opts, resultKey) {
    if (Ember.testing) {
      opts.awaitRefetchQueries = true;
    }

    return this._super(opts, resultKey);
  }
});

Examples of how we use those functions:

  • fetchMore for pagination
  • refetch for searches
  • mutation with refetchQueries for deletes

Disclaimer

We are not mocking our API. Our API has a sandbox server for tests. Maybe mocks are obfuscating this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions