Skip to content

Commit 4a6e86a

Browse files
authored
optimize useQuery result handling (#11954)
* remove unused code path Coverage shows that this code path was never hit - in the case of a `standby` fetchPolicy, `resultData.current` would already have been reset in `useResubscribeIfNecessary` * move code from `toQueryResult` to `setResult` While there are three code paths to `toQueryResult`, the other two are guaranteed to never have an `errors` property * add undocumented `errors` field to types and deprecate it * remove `useHandleSkip` instead, we calculate and memoize an "override result" in `useObservableSubscriptionResult` * remove now-obsolete `originalResult` symbol property * fix typo, chores * adjustment for compiler compat * review feedback * changeset * api-report
1 parent 0de03af commit 4a6e86a

16 files changed

+95
-123
lines changed

Diff for: .api-reports/api-report-core.api.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -2303,8 +2303,7 @@ interface WriteContext extends ReadMergeModifyContext {
23032303
// src/core/QueryManager.ts:124:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
23042304
// src/core/QueryManager.ts:158:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts
23052305
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
2306-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
2307-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
2306+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
23082307
// src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts
23092308

23102309
// (No @packageDocumentation comment for this package)

Diff for: .api-reports/api-report-react.api.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,8 @@ export interface QueryResult<TData = any, TVariables extends OperationVariables
16951695
client: ApolloClient<any>;
16961696
data: TData | undefined;
16971697
error?: ApolloError;
1698+
// @deprecated (undocumented)
1699+
errors?: ReadonlyArray<GraphQLFormattedError>;
16981700
loading: boolean;
16991701
networkStatus: NetworkStatus;
17001702
observable: ObservableQuery<TData, TVariables>;
@@ -2328,8 +2330,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
23282330
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
23292331
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
23302332
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
2331-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
2332-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
2333+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
23332334
// src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts
23342335
// src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
23352336
// src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts

Diff for: .api-reports/api-report-react_components.api.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,8 @@ interface QueryResult<TData = any, TVariables extends OperationVariables = Opera
14991499
client: ApolloClient<any>;
15001500
data: TData | undefined;
15011501
error?: ApolloError;
1502+
// @deprecated (undocumented)
1503+
errors?: ReadonlyArray<GraphQLFormattedError>;
15021504
loading: boolean;
15031505
networkStatus: NetworkStatus;
15041506
observable: ObservableQuery<TData, TVariables>;
@@ -1807,8 +1809,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
18071809
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
18081810
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
18091811
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
1810-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
1811-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
1812+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
18121813

18131814
// (No @packageDocumentation comment for this package)
18141815

Diff for: .api-reports/api-report-react_context.api.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,8 @@ interface QueryResult<TData = any, TVariables extends OperationVariables = Opera
14271427
client: ApolloClient<any>;
14281428
data: TData | undefined;
14291429
error?: ApolloError;
1430+
// @deprecated (undocumented)
1431+
errors?: ReadonlyArray<GraphQLFormattedError>;
14301432
loading: boolean;
14311433
networkStatus: NetworkStatus;
14321434
observable: ObservableQuery<TData, TVariables>;
@@ -1727,8 +1729,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
17271729
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
17281730
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
17291731
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
1730-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
1731-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
1732+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
17321733

17331734
// (No @packageDocumentation comment for this package)
17341735

Diff for: .api-reports/api-report-react_hoc.api.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1756,8 +1756,7 @@ export function withSubscription<TProps extends TGraphQLVariables | {} = {}, TDa
17561756
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
17571757
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
17581758
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
1759-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
1760-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
1759+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
17611760

17621761
// (No @packageDocumentation comment for this package)
17631762

Diff for: .api-reports/api-report-react_hooks.api.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,8 @@ interface QueryResult<TData = any, TVariables extends OperationVariables = Opera
15601560
client: ApolloClient<any>;
15611561
data: TData | undefined;
15621562
error?: ApolloError;
1563+
// @deprecated (undocumented)
1564+
errors?: ReadonlyArray<GraphQLFormattedError>;
15631565
loading: boolean;
15641566
networkStatus: NetworkStatus;
15651567
observable: ObservableQuery<TData, TVariables>;
@@ -2152,8 +2154,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
21522154
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
21532155
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
21542156
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
2155-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
2156-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
2157+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
21572158
// src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts
21582159
// src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
21592160
// src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts

Diff for: .api-reports/api-report-react_internal.api.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,8 @@ interface QueryResult<TData = any, TVariables extends OperationVariables = Opera
16221622
client: ApolloClient<any>;
16231623
data: TData | undefined;
16241624
error?: ApolloError;
1625+
// @deprecated (undocumented)
1626+
errors?: ReadonlyArray<GraphQLFormattedError>;
16251627
loading: boolean;
16261628
networkStatus: NetworkStatus;
16271629
observable: ObservableQuery<TData, TVariables>;
@@ -2215,8 +2217,7 @@ export function wrapQueryRef<TData, TVariables extends OperationVariables>(inter
22152217
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
22162218
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
22172219
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
2218-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
2219-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
2220+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
22202221
// src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts
22212222
// src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
22222223
// src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts

Diff for: .api-reports/api-report-react_ssr.api.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,8 @@ interface QueryResult<TData = any, TVariables extends OperationVariables = Opera
14121412
client: ApolloClient<any>;
14131413
data: TData | undefined;
14141414
error?: ApolloError;
1415+
// @deprecated (undocumented)
1416+
errors?: ReadonlyArray<GraphQLFormattedError>;
14151417
loading: boolean;
14161418
networkStatus: NetworkStatus;
14171419
observable: ObservableQuery<TData, TVariables>;
@@ -1712,8 +1714,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
17121714
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
17131715
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
17141716
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
1715-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
1716-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
1717+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
17171718

17181719
// (No @packageDocumentation comment for this package)
17191720

Diff for: .api-reports/api-report-testing.api.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1782,8 +1782,7 @@ export function withWarningSpy<TArgs extends any[], TResult>(it: (...args: TArgs
17821782
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
17831783
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
17841784
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
1785-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
1786-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
1785+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
17871786

17881787
// (No @packageDocumentation comment for this package)
17891788

Diff for: .api-reports/api-report-testing_core.api.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1739,8 +1739,7 @@ export function withWarningSpy<TArgs extends any[], TResult>(it: (...args: TArgs
17391739
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
17401740
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
17411741
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
1742-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
1743-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
1742+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
17441743

17451744
// (No @packageDocumentation comment for this package)
17461745

Diff for: .api-reports/api-report-utilities.api.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -2670,8 +2670,7 @@ interface WriteContext extends ReadMergeModifyContext {
26702670
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
26712671
// src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts
26722672
// src/core/types.ts:203:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
2673-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
2674-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
2673+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
26752674
// src/utilities/graphql/storeUtils.ts:226:12 - (ae-forgotten-export) The symbol "storeKeyNameStringify" needs to be exported by the entry point index.d.ts
26762675
// src/utilities/policies/pagination.ts:76:3 - (ae-forgotten-export) The symbol "TRelayEdge" needs to be exported by the entry point index.d.ts
26772676
// src/utilities/policies/pagination.ts:77:3 - (ae-forgotten-export) The symbol "TRelayPageInfo" needs to be exported by the entry point index.d.ts

Diff for: .api-reports/api-report.api.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,8 @@ export interface QueryResult<TData = any, TVariables extends OperationVariables
22662266
client: ApolloClient<any>;
22672267
data: TData | undefined;
22682268
error?: ApolloError;
2269+
// @deprecated (undocumented)
2270+
errors?: ReadonlyArray<GraphQLFormattedError>;
22692271
loading: boolean;
22702272
networkStatus: NetworkStatus;
22712273
observable: ObservableQuery<TData, TVariables>;
@@ -3016,8 +3018,7 @@ interface WriteContext extends ReadMergeModifyContext {
30163018
// src/core/QueryManager.ts:124:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
30173019
// src/core/QueryManager.ts:158:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts
30183020
// src/core/QueryManager.ts:391:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
3019-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
3020-
// src/core/watchQueryOptions.ts:272:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
3021+
// src/core/watchQueryOptions.ts:275:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
30213022
// src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts
30223023
// src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts
30233024
// src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts

Diff for: .changeset/proud-humans-begin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
Document (and deprecate) the previously undocumented `errors` property on the `useQuery` `QueryResult` type.

Diff for: .size-limits.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"dist/apollo-client.min.cjs": 40206,
2+
"dist/apollo-client.min.cjs": 40162,
33
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32999
44
}

0 commit comments

Comments
 (0)