Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updateQuery of subscribeToMore should be optional #879

Closed
wants to merge 8 commits into from
19 changes: 9 additions & 10 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,14 @@ export class ObservableQuery extends Observable<ApolloQueryResult> {
const reducer = options.updateQuery;

const subscription = observable.subscribe({
next: (data) => {
error: (err) => {
if (options.onError) {
options.onError(err);
} else {
console.error('Unhandled GraphQL subscription errror', err);
}
},
next: reducer ? (data) => {
const mapFn = (previousResult: Object, { variables }: { variables: Object }) => {
return reducer(
previousResult, {
Expand All @@ -240,16 +247,8 @@ export class ObservableQuery extends Observable<ApolloQueryResult> {
);
};
this.updateQuery(mapFn);
},
error: (err) => {
if (options.onError) {
options.onError(err);
} else {
console.error('Unhandled GraphQL subscription errror', err);
}
},
} : () => {}
});

this.subscriptionHandles.push(subscription);

return () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/watchQueryOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface FetchMoreQueryOptions {
export type SubscribeToMoreOptions = {
document: Document;
variables?: { [key: string]: any };
updateQuery: (previousQueryResult: Object, options: {
updateQuery?: (previousQueryResult: Object, options: {
subscriptionData: { data: any },
variables: { [key: string]: any },
}) => Object;
Expand Down