-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
tighten QueryTuple to indicate observable fields may be absent #5935
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<TData, TVariables> extends OperationData { | |
networkStatus: NetworkStatus.ready, | ||
called: false, | ||
data: undefined | ||
} as QueryResult<TData, TVariables> | ||
} | ||
] | ||
: [this.runLazyQuery, this.execute()]; | ||
} | ||
|
@@ -84,13 +85,13 @@ export class QueryData<TData, TVariables> extends OperationData { | |
queryResult, | ||
lazy = false, | ||
}: { | ||
queryResult: QueryResult<TData, TVariables>; | ||
queryResult: QueryResult<TData, TVariables> | LazyQueryResult<TData, TVariables>; | ||
lazy?: boolean; | ||
}) { | ||
this.isMounted = true; | ||
|
||
if (!lazy || this.runLazy) { | ||
this.handleErrorOrCompleted(queryResult); | ||
this.handleErrorOrCompleted(queryResult as QueryResult<TData, TVariables>); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// When the component is done rendering stored query errors, we'll | ||
// remove those errors from the `ObservableQuery` query store, so they | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ export interface QueryResult<TData = any, TVariables = OperationVariables> | |
error?: ApolloError; | ||
loading: boolean; | ||
networkStatus: NetworkStatus; | ||
called: boolean; | ||
called: true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assuming this field does not mean anything outside of lazy results, I believe this is correct now, as of the preceding commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, I was wondering why you think this is correct.
I spotted this strange type declaration because I'm getting an @typescript-eslint/no-unnecessary-condition warning on In my interpretation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's been ages, but I think you're right that I meant to have LazyQueryResult set |
||
} | ||
|
||
export interface QueryDataOptions<TData = any, TVariables = OperationVariables> | ||
|
@@ -123,9 +123,32 @@ export interface QueryLazyOptions<TVariables> { | |
context?: Context; | ||
} | ||
|
||
type UnexecutedLazyFields = { | ||
loading: false; | ||
networkStatus: NetworkStatus.ready; | ||
called: false; | ||
data: undefined; | ||
} | ||
|
||
type Impartial<T> = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. named as such as a complement to |
||
[P in keyof T]?: never; | ||
} | ||
|
||
type AbsentLazyResultFields = | ||
Omit< | ||
Impartial<QueryResult<unknown, unknown>>, | ||
keyof UnexecutedLazyFields> | ||
|
||
type UnexecutedLazyResult = | ||
UnexecutedLazyFields & AbsentLazyResultFields | ||
|
||
export type LazyQueryResult<TData, TVariables> = | ||
| UnexecutedLazyResult | ||
| QueryResult<TData, TVariables>; | ||
|
||
export type QueryTuple<TData, TVariables> = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW: was tempted to rename this to |
||
(options?: QueryLazyOptions<TVariables>) => void, | ||
QueryResult<TData, TVariables> | ||
LazyQueryResult<TData, TVariables> | ||
]; | ||
|
||
/* Mutation types */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is redundant (since
LazyQueryResult<D,V>
already includesQueryResult<D,V>
) but this felt like a reasonable duplication in the interest of clarity (since both lazy and non-lazy paths go through here).