Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ember-graphql/ember-apollo-client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: tallarium/ember-apollo-client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 4 commits
  • 1 file changed
  • 2 contributors

Commits on Feb 23, 2021

  1. Don't immediately resolve.

    henrywalton committed Feb 23, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    86f391e View commit details
  2. Handle error on subscription failure

    henrywalton committed Feb 23, 2021
    Copy the full SHA
    841a736 View commit details
  3. Annotations

    henrywalton committed Feb 23, 2021
    Copy the full SHA
    2471e73 View commit details

Commits on Feb 24, 2021

  1. Merge pull request #1 from tallarium/subscription-error

    Handle subscription error
    eboshii authored Feb 24, 2021
    Copy the full SHA
    4882591 View commit details
Showing with 24 additions and 21 deletions.
  1. +24 −21 addon/services/apollo.js
45 changes: 24 additions & 21 deletions addon/services/apollo.js
Original file line number Diff line number Diff line change
@@ -240,41 +240,44 @@ export default class ApolloService extends Service {
* the resolved data when the route or component is torn down. That tells
* Apollo to stop trying to send updated data to a non-existent listener.
*
* @callback errorCallback
* @param {Error} error
*
* @method subscribe
* @param {!Object} opts The query options used in the Apollo Client subscribe.
* @param {String} resultKey The key that will be returned from the resulting response data. If null or undefined, the entire response data will be returned.
* @param {errorCallback} errorHandle The callback that handles subscription errors.
* @return {!Promise}
* @public
*/
subscribe(opts, resultKey = null) {
subscribe(opts, resultKey = null, errorHandle = null) {
const observable = this.client.subscribe(opts);

const obj = new EmberApolloSubscription();

return waitForPromise(
new RSVP.Promise((resolve, reject) => {
let subscription = observable.subscribe({
next: (newData) => {
let dataToSend = extractNewData(resultKey, newData);
if (dataToSend === null) {
// see comment in extractNewData
return;
}

run(() => obj._onNewData(dataToSend));
},
error(e) {
reject(e);
},
return waitForPromise(new RSVP.Promise((resolve, reject) => {
let subscription = observable.subscribe({
next: (newData) => {
let dataToSend = extractNewData(resultKey, newData);
if (dataToSend === null) {
// see comment in extractNewData
return;
}

run(() => obj._onNewData(dataToSend));
},
error(e) {
if (errorHandle) {
errorHandle(e);
}
reject(e);
}
});

obj._apolloClientSubscription = subscription;

resolve(obj);
})
);
}));
}


/**
* Executes a single `query` on the Apollo client. The resolved object will
* never be updated and does not have to be unsubscribed.