From 9fc6bc0724781f8e2af512a878b8b83171f8b528 Mon Sep 17 00:00:00 2001 From: Ian Grayson Date: Thu, 11 Aug 2016 12:40:20 -0700 Subject: [PATCH] Transform watchQuery.fetch results --- src/ObservableQuery.ts | 3 ++- src/QueryManager.ts | 18 +++++++++--------- typings/main/globals/node/index.d.ts | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ObservableQuery.ts b/src/ObservableQuery.ts index 44512b092a2..c8d700f9c4b 100644 --- a/src/ObservableQuery.ts +++ b/src/ObservableQuery.ts @@ -104,7 +104,8 @@ export class ObservableQuery extends Observable { 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) => { diff --git a/src/QueryManager.ts b/src/QueryManager.ts index 9e21d120845..0bfba00c80a 100644 --- a/src/QueryManager.ts +++ b/src/QueryManager.ts @@ -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, @@ -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) => { diff --git a/typings/main/globals/node/index.d.ts b/typings/main/globals/node/index.d.ts index ccbe6facd00..56569c5ef9e 100644 --- a/typings/main/globals/node/index.d.ts +++ b/typings/main/globals/node/index.d.ts @@ -2298,4 +2298,4 @@ declare module "constants" { export var W_OK: number; export var X_OK: number; export var UV_UDP_REUSEADDR: number; -} \ No newline at end of file +}