From 550e42ed3f0c88dcfee80490334b9f0f344a55c5 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 11 Feb 2020 10:26:04 -0500 Subject: [PATCH 1/2] tighten QueryTuple to indicate observable fields may be absent if called==false fixes #5933 --- src/react/data/QueryData.ts | 9 +++++---- src/react/types/types.ts | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/react/data/QueryData.ts b/src/react/data/QueryData.ts index a1ed59e5c06..673e5df55bf 100644 --- a/src/react/data/QueryData.ts +++ b/src/react/data/QueryData.ts @@ -18,7 +18,8 @@ import { QueryCurrentObservable, QueryTuple, QueryLazyOptions, - ObservableQueryFields + ObservableQueryFields, + LazyQueryResult } from '../types/types'; import { OperationData } from './OperationData'; @@ -68,7 +69,7 @@ export class QueryData extends OperationData { networkStatus: NetworkStatus.ready, called: false, data: undefined - } as QueryResult + } ] : [this.runLazyQuery, this.execute()]; } @@ -84,13 +85,13 @@ export class QueryData extends OperationData { queryResult, lazy = false, }: { - queryResult: QueryResult; + queryResult: QueryResult | LazyQueryResult; lazy?: boolean; }) { this.isMounted = true; if (!lazy || this.runLazy) { - this.handleErrorOrCompleted(queryResult); + this.handleErrorOrCompleted(queryResult as QueryResult); // When the component is done rendering stored query errors, we'll // remove those errors from the `ObservableQuery` query store, so they diff --git a/src/react/types/types.ts b/src/react/types/types.ts index 415efe694d8..e42a70d2c2a 100644 --- a/src/react/types/types.ts +++ b/src/react/types/types.ts @@ -123,9 +123,32 @@ export interface QueryLazyOptions { context?: Context; } +type UnexecutedLazyFields = { + loading: false; + networkStatus: NetworkStatus.ready; + called: false; + data: undefined; +} + +type Impartial = { + [P in keyof T]?: never; +} + +type AbsentLazyResultFields = + Omit< + Impartial>, + keyof UnexecutedLazyFields> + +type UnexecutedLazyResult = + UnexecutedLazyFields & AbsentLazyResultFields + +export type LazyQueryResult = + | UnexecutedLazyResult + | QueryResult; + export type QueryTuple = [ (options?: QueryLazyOptions) => void, - QueryResult + LazyQueryResult ]; /* Mutation types */ From 73659fc5256b21f2f3994fa72a1f2d5fb3f9ea41 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 11 Feb 2020 10:40:23 -0500 Subject: [PATCH 2/2] full QueryResult always implies `called: true` (#5933) --- src/react/types/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/react/types/types.ts b/src/react/types/types.ts index e42a70d2c2a..e8e3eacab40 100644 --- a/src/react/types/types.ts +++ b/src/react/types/types.ts @@ -82,7 +82,7 @@ export interface QueryResult error?: ApolloError; loading: boolean; networkStatus: NetworkStatus; - called: boolean; + called: true; } export interface QueryDataOptions