Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
fix(stitching): observabeToAsyncIterator should preserve graphql errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Sep 22, 2019
1 parent 83af6f2 commit 86bf0e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/stitching/makeRemoteExecutableSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import resolveParentFromTypename from './resolveFromParentTypename';
import defaultMergedResolver from './defaultMergedResolver';
import { checkResultAndHandleErrors } from './checkResultAndHandleErrors';
import { observableToAsyncIterable } from './observableToAsyncIterable';
import mapAsyncIterator from './mapAsyncIterator';
import { Options as PrintSchemaOptions } from 'graphql/utilities/schemaPrinter';

export type ResolverFn = (
Expand Down Expand Up @@ -181,7 +182,9 @@ function createSubscriptionResolver(name: string, link: ApolloLink): ResolverFn
};

const observable = execute(link, operation);

return observableToAsyncIterable(observable);
const originalAsyncIterator = observableToAsyncIterable(observable);
return mapAsyncIterator(originalAsyncIterator, result => ({
[info.fieldName]: checkResultAndHandleErrors(result, info),
}));
};
}
6 changes: 3 additions & 3 deletions src/stitching/observableToAsyncIterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export function observableToAsyncIterable<T>(observable: Observable<T>): AsyncIt

let listening = true;

const pushValue = ({ data }: any) => {
const pushValue = (value: any) => {
if (pullQueue.length !== 0) {
pullQueue.shift()({ value: data, done: false });
pullQueue.shift()({ value, done: false });
} else {
pushQueue.push({ value: data });
pushQueue.push({ value });
}
};

Expand Down

0 comments on commit 86bf0e3

Please sign in to comment.