Skip to content

Commit

Permalink
Transform watchQuery.fetch results
Browse files Browse the repository at this point in the history
  • Loading branch information
igrayson authored and nevir committed Aug 11, 2016
1 parent 6d9e501 commit 9fc6bc0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export class ObservableQuery extends Observable<ApolloQueryResult> {
return this.queryManager.fetchQuery(this.queryId, assign(this.options, {
forceFetch: true,
variables,
}) as WatchQueryOptions);
}) as WatchQueryOptions)
.then(result => this.queryManager.transformResult(result));
};

this.fetchMore = (fetchMoreOptions: WatchQueryOptions & FetchMoreOptions) => {
Expand Down
18 changes: 9 additions & 9 deletions src/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,15 @@ export class QueryManager {
};
}

// Give the result transformer a chance to observe or modify result data before it is passed on.
public transformResult(result: ApolloQueryResult): ApolloQueryResult {
if (!this.resultTransformer) {
return result;
} else {
return this.resultTransformer(result);
}
}

private collectResultBehaviorsFromUpdateQueries(
updateQueries: MutationQueryReducersMap,
mutationResult: Object,
Expand Down Expand Up @@ -936,15 +945,6 @@ export class QueryManager {
return !comparator(this.queryResults[queryId], result);
}

// Give the result transformer a chance to observe or modify result data before it is passed on.
private transformResult(result: ApolloQueryResult): ApolloQueryResult {
if (!this.resultTransformer) {
return result;
} else {
return this.resultTransformer(result);
}
}

private broadcastQueries() {
const queries = this.getApolloState().queries;
forOwn(this.queryListeners, (listener: QueryListener, queryId: string) => {
Expand Down
2 changes: 1 addition & 1 deletion typings/main/globals/node/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2298,4 +2298,4 @@ declare module "constants" {
export var W_OK: number;
export var X_OK: number;
export var UV_UDP_REUSEADDR: number;
}
}

0 comments on commit 9fc6bc0

Please sign in to comment.