@apollo/client 4.0.0-alpha.22 → 4.0.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +238 -2
- package/__cjs/cache/core/cache.cjs +1 -1
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.cjs +4 -4
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
- package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
- package/__cjs/core/ApolloClient.cjs +15 -13
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +8 -3
- package/__cjs/core/ObservableQuery.cjs +52 -48
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +48 -14
- package/__cjs/core/QueryInfo.cjs +146 -168
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +14 -11
- package/__cjs/core/QueryManager.cjs +121 -111
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +4 -0
- package/__cjs/core/index.cjs +2 -1
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +4 -4
- package/__cjs/core/types.d.cts +68 -15
- package/__cjs/core/watchQueryOptions.d.cts +2 -24
- package/__cjs/dev/setErrorMessageHandler.cjs.map +1 -1
- package/__cjs/errors/CombinedGraphQLErrors.cjs +6 -3
- package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedGraphQLErrors.d.cts +7 -2
- package/__cjs/errors/index.cjs +1 -1
- package/__cjs/errors/index.cjs.map +1 -1
- package/__cjs/errors/index.d.cts +1 -3
- package/__cjs/incremental/handlers/defer20220824.cjs +102 -0
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -0
- package/__cjs/incremental/handlers/defer20220824.d.cts +55 -0
- package/__cjs/incremental/handlers/notImplemented.cjs +19 -0
- package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -0
- package/__cjs/incremental/handlers/notImplemented.d.cts +9 -0
- package/__cjs/incremental/index.cjs +9 -0
- package/__cjs/incremental/index.cjs.map +1 -0
- package/__cjs/incremental/index.d.cts +4 -0
- package/__cjs/incremental/types.cjs +3 -0
- package/__cjs/incremental/types.cjs.map +1 -0
- package/__cjs/incremental/types.d.cts +24 -0
- package/__cjs/invariantErrorCodes.cjs +62 -45
- package/__cjs/link/context/index.cjs +36 -25
- package/__cjs/link/context/index.cjs.map +1 -1
- package/__cjs/link/context/index.d.cts +8 -1
- package/__cjs/link/core/types.d.cts +4 -32
- package/__cjs/link/error/index.cjs +68 -65
- package/__cjs/link/error/index.cjs.map +1 -1
- package/__cjs/link/error/index.d.cts +15 -14
- package/__cjs/link/http/BaseHttpLink.cjs +0 -6
- package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.cjs +4 -0
- package/__cjs/link/http/HttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.d.cts +4 -0
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +45 -57
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
- package/__cjs/link/index.cjs.map +1 -1
- package/__cjs/link/index.d.cts +1 -1
- package/__cjs/link/persisted-queries/index.cjs +158 -142
- package/__cjs/link/persisted-queries/index.cjs.map +1 -1
- package/__cjs/link/persisted-queries/index.d.cts +19 -19
- package/__cjs/link/remove-typename/index.cjs +2 -1
- package/__cjs/link/remove-typename/index.cjs.map +1 -1
- package/__cjs/link/remove-typename/index.d.cts +1 -1
- package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs +34 -23
- package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs.map +1 -1
- package/__cjs/link/remove-typename/removeTypenameFromVariables.d.cts +8 -9
- package/__cjs/local-state/LocalState.cjs.map +1 -1
- package/__cjs/local-state/LocalState.d.cts +3 -4
- package/__cjs/masking/types.d.cts +6 -5
- package/__cjs/react/hooks/useBackgroundQuery.cjs +1 -0
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.cjs +1 -0
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +2 -7
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +2 -2
- package/__cjs/react/hooks/useQuery.cjs +23 -21
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +3 -8
- package/__cjs/react/hooks/useQueryRefHandlers.cjs +1 -0
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useReadQuery.cjs +1 -0
- package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.cjs +1 -0
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.cjs +1 -0
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.cjs +4 -4
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.d.cts +2 -3
- package/__cjs/react/internal/types.d.cts +2 -7
- package/__cjs/utilities/graphql/isFormattedExecutionResult.cjs +9 -0
- package/__cjs/utilities/graphql/isFormattedExecutionResult.cjs.map +1 -0
- package/__cjs/utilities/graphql/isFormattedExecutionResult.d.cts +3 -0
- package/__cjs/utilities/index.cjs +3 -1
- package/__cjs/utilities/index.cjs.map +1 -1
- package/__cjs/utilities/index.d.cts +1 -0
- package/__cjs/utilities/internal/getGraphQLErrorsFromResult.cjs +1 -12
- package/__cjs/utilities/internal/getGraphQLErrorsFromResult.cjs.map +1 -1
- package/__cjs/utilities/internal/getGraphQLErrorsFromResult.d.cts +4 -2
- package/__cjs/utilities/internal/graphQLResultHasError.cjs +1 -4
- package/__cjs/utilities/internal/graphQLResultHasError.cjs.map +1 -1
- package/__cjs/utilities/internal/graphQLResultHasError.d.cts +2 -2
- package/__cjs/utilities/internal/index.cjs +2 -10
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +0 -4
- package/__cjs/version.cjs +3 -2
- package/__cjs/version.cjs.map +1 -1
- package/__cjs/version.d.cts +1 -0
- package/cache/core/cache.js +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/key-extractor.js.map +1 -1
- package/cache/inmemory/policies.js +4 -4
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +2 -2
- package/cache/inmemory/writeToStore.js +4 -4
- package/core/ApolloClient.d.ts +8 -3
- package/core/ApolloClient.js +15 -13
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +48 -14
- package/core/ObservableQuery.js +53 -49
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +14 -11
- package/core/QueryInfo.js +147 -169
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +4 -0
- package/core/QueryManager.js +123 -113
- package/core/QueryManager.js.map +1 -1
- package/core/index.d.ts +4 -4
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/core/types.d.ts +68 -15
- package/core/watchQueryOptions.d.ts +2 -24
- package/dev/setErrorMessageHandler.js.map +1 -1
- package/errors/CombinedGraphQLErrors.d.ts +7 -2
- package/errors/CombinedGraphQLErrors.js +6 -3
- package/errors/CombinedGraphQLErrors.js.map +1 -1
- package/errors/index.d.ts +1 -3
- package/errors/index.js +1 -1
- package/errors/index.js.map +1 -1
- package/incremental/handlers/defer20220824.d.ts +55 -0
- package/incremental/handlers/defer20220824.js +97 -0
- package/incremental/handlers/defer20220824.js.map +1 -0
- package/incremental/handlers/notImplemented.d.ts +9 -0
- package/incremental/handlers/notImplemented.js +15 -0
- package/incremental/handlers/notImplemented.js.map +1 -0
- package/incremental/index.d.ts +4 -0
- package/incremental/index.js +3 -0
- package/incremental/index.js.map +1 -0
- package/incremental/types.d.ts +24 -0
- package/incremental/types.js +2 -0
- package/incremental/types.js.map +1 -0
- package/invariantErrorCodes.js +63 -49
- package/legacyEntryPoints/incremental/incremental.cjs +1 -0
- package/legacyEntryPoints/incremental/incremental.d.cts +1 -0
- package/legacyEntryPoints/incremental/index.d.ts +1 -0
- package/legacyEntryPoints/incremental/index.js +1 -0
- package/link/context/index.d.ts +8 -1
- package/link/context/index.js +34 -25
- package/link/context/index.js.map +1 -1
- package/link/core/types.d.ts +4 -32
- package/link/error/index.d.ts +15 -14
- package/link/error/index.js +68 -65
- package/link/error/index.js.map +1 -1
- package/link/http/BaseHttpLink.js +1 -7
- package/link/http/BaseHttpLink.js.map +1 -1
- package/link/http/HttpLink.d.ts +4 -0
- package/link/http/HttpLink.js +4 -0
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js +45 -57
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/index.d.ts +1 -1
- package/link/index.js.map +1 -1
- package/link/persisted-queries/index.d.ts +19 -19
- package/link/persisted-queries/index.js +156 -141
- package/link/persisted-queries/index.js.map +1 -1
- package/link/remove-typename/index.d.ts +1 -1
- package/link/remove-typename/index.js +1 -1
- package/link/remove-typename/index.js.map +1 -1
- package/link/remove-typename/removeTypenameFromVariables.d.ts +8 -9
- package/link/remove-typename/removeTypenameFromVariables.js +32 -22
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/local-state/LocalState.d.ts +3 -4
- package/local-state/LocalState.js.map +1 -1
- package/masking/types.d.ts +6 -5
- package/package.json +9 -2
- package/react/hooks/useApolloClient.js +14 -1
- package/react/hooks/useApolloClient.js.map +1 -1
- package/react/hooks/useBackgroundQuery.js +7 -6
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.js +12 -11
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +2 -7
- package/react/hooks/useLazyQuery.js +15 -15
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.js +229 -69
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +2 -2
- package/react/hooks/useMutation.js +191 -81
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +3 -8
- package/react/hooks/useQuery.js +243 -70
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.js +64 -23
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useReadQuery.js +3 -2
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +4 -4
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseFragment.js +1 -0
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +59 -33
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/internal/cache/QueryReference.d.ts +2 -3
- package/react/internal/cache/QueryReference.js +4 -4
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/types.d.ts +2 -7
- package/utilities/graphql/isFormattedExecutionResult.d.ts +3 -0
- package/utilities/graphql/isFormattedExecutionResult.js +6 -0
- package/utilities/graphql/isFormattedExecutionResult.js.map +1 -0
- package/utilities/index.d.ts +1 -0
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/internal/getGraphQLErrorsFromResult.d.ts +4 -2
- package/utilities/internal/getGraphQLErrorsFromResult.js +1 -12
- package/utilities/internal/getGraphQLErrorsFromResult.js.map +1 -1
- package/utilities/internal/graphQLResultHasError.d.ts +2 -2
- package/utilities/internal/graphQLResultHasError.js +1 -4
- package/utilities/internal/graphQLResultHasError.js.map +1 -1
- package/utilities/internal/index.d.ts +0 -4
- package/utilities/internal/index.js +0 -4
- package/utilities/internal/index.js.map +1 -1
- package/version.d.ts +1 -0
- package/version.js +2 -1
- package/version.js.map +1 -1
- package/__cjs/utilities/internal/isExecutionPatchIncrementalResult.cjs +0 -12
- package/__cjs/utilities/internal/isExecutionPatchIncrementalResult.cjs.map +0 -1
- package/__cjs/utilities/internal/isExecutionPatchIncrementalResult.d.cts +0 -8
- package/__cjs/utilities/internal/isExecutionPatchIninitialResult.cjs +0 -12
- package/__cjs/utilities/internal/isExecutionPatchIninitialResult.cjs.map +0 -1
- package/__cjs/utilities/internal/isExecutionPatchIninitialResult.d.cts +0 -8
- package/__cjs/utilities/internal/isExecutionPatchResult.cjs +0 -15
- package/__cjs/utilities/internal/isExecutionPatchResult.cjs.map +0 -1
- package/__cjs/utilities/internal/isExecutionPatchResult.d.cts +0 -8
- package/__cjs/utilities/internal/mergeIncrementalData.cjs +0 -30
- package/__cjs/utilities/internal/mergeIncrementalData.cjs.map +0 -1
- package/__cjs/utilities/internal/mergeIncrementalData.d.cts +0 -8
- package/utilities/internal/isExecutionPatchIncrementalResult.d.ts +0 -8
- package/utilities/internal/isExecutionPatchIncrementalResult.js +0 -9
- package/utilities/internal/isExecutionPatchIncrementalResult.js.map +0 -1
- package/utilities/internal/isExecutionPatchIninitialResult.d.ts +0 -8
- package/utilities/internal/isExecutionPatchIninitialResult.js +0 -9
- package/utilities/internal/isExecutionPatchIninitialResult.js.map +0 -1
- package/utilities/internal/isExecutionPatchResult.d.ts +0 -8
- package/utilities/internal/isExecutionPatchResult.js +0 -12
- package/utilities/internal/isExecutionPatchResult.js.map +0 -1
- package/utilities/internal/mergeIncrementalData.d.ts +0 -8
- package/utilities/internal/mergeIncrementalData.js +0 -27
- package/utilities/internal/mergeIncrementalData.js.map +0 -1
|
@@ -6,13 +6,51 @@ import type { MissingTree } from "@apollo/client/cache";
|
|
|
6
6
|
import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
|
|
7
7
|
import type { QueryManager } from "./QueryManager.cjs";
|
|
8
8
|
import type { ApolloQueryResult, DefaultContext, OperationVariables, QueryResult, TypedDocumentNode } from "./types.cjs";
|
|
9
|
-
import type { ErrorPolicy,
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
import type { ErrorPolicy, NextFetchPolicyContext, RefetchWritePolicy, SubscribeToMoreOptions, UpdateQueryMapFn, WatchQueryFetchPolicy, WatchQueryOptions } from "./watchQueryOptions.cjs";
|
|
10
|
+
export type FetchMoreOptions<TData, TVariables extends OperationVariables, TFetchData = TData, TFetchVars extends OperationVariables = TVariables> = {
|
|
11
|
+
/**
|
|
12
|
+
* A GraphQL query string parsed into an AST with the gql template literal.
|
|
13
|
+
*
|
|
14
|
+
* @docGroup
|
|
15
|
+
*
|
|
16
|
+
* 1. Operation options
|
|
17
|
+
*/
|
|
18
|
+
query?: DocumentNode | TypedDocumentNode<TFetchData, TFetchVars>;
|
|
19
|
+
/**
|
|
20
|
+
* An object containing all of the GraphQL variables your query requires to execute.
|
|
21
|
+
*
|
|
22
|
+
* Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
|
|
23
|
+
*
|
|
24
|
+
* @docGroup
|
|
25
|
+
*
|
|
26
|
+
* 1. Operation options
|
|
27
|
+
*/
|
|
28
|
+
variables?: Partial<NoInfer<TFetchVars>>;
|
|
29
|
+
/**
|
|
30
|
+
* Specifies how the query handles a response that returns both GraphQL errors and partial results.
|
|
31
|
+
*
|
|
32
|
+
* For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
|
|
33
|
+
*
|
|
34
|
+
* The default value is `none`, meaning that the query result includes error details but not partial results.
|
|
35
|
+
*
|
|
36
|
+
* @docGroup
|
|
37
|
+
*
|
|
38
|
+
* 1. Operation options
|
|
39
|
+
*/
|
|
40
|
+
errorPolicy?: ErrorPolicy;
|
|
41
|
+
/**
|
|
42
|
+
* If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain.
|
|
43
|
+
*
|
|
44
|
+
* @docGroup
|
|
45
|
+
*
|
|
46
|
+
* 2. Networking options
|
|
47
|
+
*/
|
|
48
|
+
context?: DefaultContext;
|
|
49
|
+
updateQuery?: (previousQueryResult: Unmasked<TData>, options: {
|
|
50
|
+
fetchMoreResult: Unmasked<TFetchData>;
|
|
51
|
+
variables: TFetchVars;
|
|
52
|
+
}) => Unmasked<TData>;
|
|
53
|
+
};
|
|
16
54
|
export declare namespace ObservableQuery {
|
|
17
55
|
type Options<TData = unknown, TVariables extends OperationVariables = OperationVariables> = {
|
|
18
56
|
/**
|
|
@@ -232,12 +270,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
232
270
|
/**
|
|
233
271
|
* A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
|
|
234
272
|
*/
|
|
235
|
-
fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(
|
|
236
|
-
updateQuery?: (previousQueryResult: Unmasked<TData>, options: {
|
|
237
|
-
fetchMoreResult: Unmasked<TFetchData>;
|
|
238
|
-
variables: TFetchVars;
|
|
239
|
-
}) => Unmasked<TData>;
|
|
240
|
-
}): Promise<QueryResult<TFetchData>>;
|
|
273
|
+
fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>({ query, variables, context, errorPolicy, updateQuery, }: FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars>): Promise<QueryResult<TFetchData>>;
|
|
241
274
|
/**
|
|
242
275
|
* A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
|
|
243
276
|
*
|
|
@@ -249,7 +282,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
249
282
|
*
|
|
250
283
|
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
251
284
|
*/
|
|
252
|
-
|
|
285
|
+
applyOptions(newOptions: Partial<ObservableQuery.Options<TData, TVariables>>): void;
|
|
253
286
|
/**
|
|
254
287
|
* Update the variables of this observable query, and fetch the new results
|
|
255
288
|
* if they've changed. Most users should prefer `refetch` instead of
|
|
@@ -285,6 +318,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
285
318
|
stopPolling(): void;
|
|
286
319
|
private applyNextFetchPolicy;
|
|
287
320
|
private fetch;
|
|
321
|
+
private didWarnCacheOnlyPolling;
|
|
288
322
|
private updatePolling;
|
|
289
323
|
private cancelPolling;
|
|
290
324
|
/**
|
package/__cjs/core/QueryInfo.cjs
CHANGED
|
@@ -39,6 +39,7 @@ class QueryInfo {
|
|
|
39
39
|
queryManager;
|
|
40
40
|
id;
|
|
41
41
|
observableQuery;
|
|
42
|
+
incremental;
|
|
42
43
|
constructor(queryManager, observableQuery) {
|
|
43
44
|
const cache = (this.cache = queryManager.cache);
|
|
44
45
|
const id = (queryInfoIds.get(queryManager) || 0) + 1;
|
|
@@ -85,8 +86,20 @@ class QueryInfo {
|
|
|
85
86
|
(0, equality_1.equal)(variables, lastWrite.variables) &&
|
|
86
87
|
(0, equality_1.equal)(result.data, lastWrite.result.data));
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
get hasNext() {
|
|
90
|
+
return this.incremental ? this.incremental.hasNext : false;
|
|
91
|
+
}
|
|
92
|
+
maybeHandleIncrementalResult(cacheData, incoming, query) {
|
|
93
|
+
const { incrementalHandler } = this.queryManager;
|
|
94
|
+
if (incrementalHandler.isIncrementalResult(incoming)) {
|
|
95
|
+
this.incremental ||= incrementalHandler.startRequest({
|
|
96
|
+
query,
|
|
97
|
+
});
|
|
98
|
+
return this.incremental.handle(cacheData, incoming);
|
|
99
|
+
}
|
|
100
|
+
return incoming;
|
|
101
|
+
}
|
|
102
|
+
markQueryResult(incoming, { document: query, variables, errorPolicy, cacheWriteBehavior, }) {
|
|
90
103
|
const diffOptions = {
|
|
91
104
|
query,
|
|
92
105
|
variables,
|
|
@@ -96,147 +109,130 @@ class QueryInfo {
|
|
|
96
109
|
// Cancel the pending notify timeout (if it exists) to prevent extraneous network
|
|
97
110
|
// requests. To allow future notify timeouts, diff and dirty are reset as well.
|
|
98
111
|
this.observableQuery?.["resetNotifications"]();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.lastDiff = {
|
|
105
|
-
diff: { result: result.data, complete: true },
|
|
106
|
-
options: diffOptions,
|
|
107
|
-
};
|
|
112
|
+
const skipCache = cacheWriteBehavior === 0 /* CacheWriteBehavior.FORBID */;
|
|
113
|
+
const lastDiff = skipCache ? undefined : this.cache.diff(diffOptions);
|
|
114
|
+
let result = this.maybeHandleIncrementalResult(lastDiff?.result, incoming, query);
|
|
115
|
+
if (skipCache) {
|
|
116
|
+
return result;
|
|
108
117
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// received, when possible.
|
|
177
|
-
result.data = lastDiff.result;
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
// If the previous this.diff was incomplete, fall through to
|
|
181
|
-
// re-reading the latest data with cache.diff, below.
|
|
182
|
-
}
|
|
183
|
-
const diff = cache.diff(diffOptions);
|
|
184
|
-
// If we're allowed to write to the cache, and we can read a
|
|
185
|
-
// complete result from the cache, update result.data to be the
|
|
186
|
-
// result from the cache, rather than the raw network result.
|
|
187
|
-
// Set without setDiff to avoid triggering a notify call, since
|
|
188
|
-
// we have other ways of notifying for this result.
|
|
189
|
-
if (diff.complete) {
|
|
190
|
-
result.data = diff.result;
|
|
118
|
+
if (shouldWriteResult(result, errorPolicy)) {
|
|
119
|
+
// Using a transaction here so we have a chance to read the result
|
|
120
|
+
// back from the cache before the watch callback fires as a result
|
|
121
|
+
// of writeQuery, so we can store the new diff quietly and ignore
|
|
122
|
+
// it when we receive it redundantly from the watch callback.
|
|
123
|
+
this.cache.batch({
|
|
124
|
+
onWatchUpdated: (
|
|
125
|
+
// all additional options on ObservableQuery.CacheWatchOptions are
|
|
126
|
+
// optional so we can use the type here
|
|
127
|
+
watch, diff) => {
|
|
128
|
+
if (watch.watcher === this.observableQuery) {
|
|
129
|
+
// see comment on `lastOwnDiff` for explanation
|
|
130
|
+
watch.lastOwnDiff = diff;
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
update: (cache) => {
|
|
134
|
+
if (this.shouldWrite(result, variables)) {
|
|
135
|
+
cache.writeQuery({
|
|
136
|
+
query,
|
|
137
|
+
data: result.data,
|
|
138
|
+
variables,
|
|
139
|
+
overwrite: cacheWriteBehavior === 1 /* CacheWriteBehavior.OVERWRITE */,
|
|
140
|
+
});
|
|
141
|
+
this.lastWrite = {
|
|
142
|
+
result,
|
|
143
|
+
variables,
|
|
144
|
+
dmCount: destructiveMethodCounts.get(this.cache),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// If result is the same as the last result we received from
|
|
149
|
+
// the network (and the variables match too), avoid writing
|
|
150
|
+
// result into the cache again. The wisdom of skipping this
|
|
151
|
+
// cache write is far from obvious, since any cache write
|
|
152
|
+
// could be the one that puts the cache back into a desired
|
|
153
|
+
// state, fixing corruption or missing data. However, if we
|
|
154
|
+
// always write every network result into the cache, we enable
|
|
155
|
+
// feuds between queries competing to update the same data in
|
|
156
|
+
// incompatible ways, which can lead to an endless cycle of
|
|
157
|
+
// cache broadcasts and useless network requests. As with any
|
|
158
|
+
// feud, eventually one side must step back from the brink,
|
|
159
|
+
// letting the other side(s) have the last word(s). There may
|
|
160
|
+
// be other points where we could break this cycle, such as
|
|
161
|
+
// silencing the broadcast for cache.writeQuery (not a good
|
|
162
|
+
// idea, since it just delays the feud a bit) or somehow
|
|
163
|
+
// avoiding the network request that just happened (also bad,
|
|
164
|
+
// because the server could return useful new data). All
|
|
165
|
+
// options considered, skipping this cache write seems to be
|
|
166
|
+
// the least damaging place to break the cycle, because it
|
|
167
|
+
// reflects the intuition that we recently wrote this exact
|
|
168
|
+
// result into the cache, so the cache *should* already/still
|
|
169
|
+
// contain this data. If some other query has clobbered that
|
|
170
|
+
// data in the meantime, that's too bad, but there will be no
|
|
171
|
+
// winners if every query blindly reverts to its own version
|
|
172
|
+
// of the data. This approach also gives the network a chance
|
|
173
|
+
// to return new data, which will be written into the cache as
|
|
174
|
+
// usual, notifying only those queries that are directly
|
|
175
|
+
// affected by the cache updates, as usual. In the future, an
|
|
176
|
+
// even more sophisticated cache could perhaps prevent or
|
|
177
|
+
// mitigate the clobbering somehow, but that would make this
|
|
178
|
+
// particular cache write even less important, and thus
|
|
179
|
+
// skipping it would be even safer than it is today.
|
|
180
|
+
if (lastDiff && lastDiff.complete) {
|
|
181
|
+
// Reuse data from the last good (complete) diff that we
|
|
182
|
+
// received, when possible.
|
|
183
|
+
result = { ...result, data: lastDiff.result };
|
|
184
|
+
return;
|
|
191
185
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
186
|
+
// If the previous this.diff was incomplete, fall through to
|
|
187
|
+
// re-reading the latest data with cache.diff, below.
|
|
188
|
+
}
|
|
189
|
+
const diff = cache.diff(diffOptions);
|
|
190
|
+
// If we're allowed to write to the cache, and we can read a
|
|
191
|
+
// complete result from the cache, update result.data to be the
|
|
192
|
+
// result from the cache, rather than the raw network result.
|
|
193
|
+
// Set without setDiff to avoid triggering a notify call, since
|
|
194
|
+
// we have other ways of notifying for this result.
|
|
195
|
+
if (diff.complete) {
|
|
196
|
+
result = { ...result, data: diff.result };
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
});
|
|
198
200
|
}
|
|
201
|
+
else {
|
|
202
|
+
this.lastWrite = void 0;
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
199
205
|
}
|
|
200
|
-
markMutationResult(
|
|
206
|
+
markMutationResult(incoming, mutation, cache = this.cache) {
|
|
201
207
|
const cacheWrites = [];
|
|
202
208
|
const skipCache = mutation.cacheWriteBehavior === 0 /* CacheWriteBehavior.FORBID */;
|
|
209
|
+
let result = this.maybeHandleIncrementalResult(skipCache ? undefined : (cache.diff({
|
|
210
|
+
id: "ROOT_MUTATION",
|
|
211
|
+
// The cache complains if passed a mutation where it expects a
|
|
212
|
+
// query, so we transform mutations and subscriptions to queries
|
|
213
|
+
// (only once, thanks to this.transformCache).
|
|
214
|
+
query: this.queryManager.getDocumentInfo(mutation.document).asQuery,
|
|
215
|
+
variables: mutation.variables,
|
|
216
|
+
optimistic: false,
|
|
217
|
+
returnPartialData: true,
|
|
218
|
+
}).result), incoming, mutation.document);
|
|
219
|
+
if (mutation.errorPolicy === "ignore") {
|
|
220
|
+
result = { ...result, errors: [] };
|
|
221
|
+
}
|
|
222
|
+
if ((0, internal_1.graphQLResultHasError)(result) && mutation.errorPolicy === "none") {
|
|
223
|
+
return Promise.resolve(result);
|
|
224
|
+
}
|
|
225
|
+
const getResultWithDataState = () => ({
|
|
226
|
+
...result,
|
|
227
|
+
dataState: this.hasNext ? "streaming" : "complete",
|
|
228
|
+
});
|
|
203
229
|
if (!skipCache && shouldWriteResult(result, mutation.errorPolicy)) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
if ((0, internal_1.isExecutionPatchIncrementalResult)(result) &&
|
|
213
|
-
(0, internal_1.isNonEmptyArray)(result.incremental)) {
|
|
214
|
-
const diff = cache.diff({
|
|
215
|
-
id: "ROOT_MUTATION",
|
|
216
|
-
// The cache complains if passed a mutation where it expects a
|
|
217
|
-
// query, so we transform mutations and subscriptions to queries
|
|
218
|
-
// (only once, thanks to this.transformCache).
|
|
219
|
-
query: this.queryManager.getDocumentInfo(mutation.document).asQuery,
|
|
220
|
-
variables: mutation.variables,
|
|
221
|
-
optimistic: false,
|
|
222
|
-
returnPartialData: true,
|
|
223
|
-
});
|
|
224
|
-
let mergedData;
|
|
225
|
-
if (diff.result) {
|
|
226
|
-
mergedData = (0, internal_1.mergeIncrementalData)(diff.result, result);
|
|
227
|
-
}
|
|
228
|
-
if (typeof mergedData !== "undefined") {
|
|
229
|
-
// cast the ExecutionPatchResult to FetchResult here since
|
|
230
|
-
// ExecutionPatchResult never has `data` when returned from the server
|
|
231
|
-
result.data = mergedData;
|
|
232
|
-
cacheWrites.push({
|
|
233
|
-
result: mergedData,
|
|
234
|
-
dataId: "ROOT_MUTATION",
|
|
235
|
-
query: mutation.document,
|
|
236
|
-
variables: mutation.variables,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
}
|
|
230
|
+
cacheWrites.push({
|
|
231
|
+
result: result.data,
|
|
232
|
+
dataId: "ROOT_MUTATION",
|
|
233
|
+
query: mutation.document,
|
|
234
|
+
variables: mutation.variables,
|
|
235
|
+
});
|
|
240
236
|
const { updateQueries } = mutation;
|
|
241
237
|
if (updateQueries) {
|
|
242
238
|
this.queryManager
|
|
@@ -254,7 +250,7 @@ class QueryInfo {
|
|
|
254
250
|
if (complete && currentQueryResult) {
|
|
255
251
|
// Run our reducer using the current query result and the mutation result.
|
|
256
252
|
const nextQueryResult = updater(currentQueryResult, {
|
|
257
|
-
mutationResult:
|
|
253
|
+
mutationResult: getResultWithDataState(),
|
|
258
254
|
queryName: (document && (0, internal_1.getOperationName)(document)) || void 0,
|
|
259
255
|
queryVariables: variables,
|
|
260
256
|
});
|
|
@@ -271,8 +267,12 @@ class QueryInfo {
|
|
|
271
267
|
});
|
|
272
268
|
}
|
|
273
269
|
}
|
|
270
|
+
let refetchQueries = mutation.refetchQueries;
|
|
271
|
+
if (typeof refetchQueries === "function") {
|
|
272
|
+
refetchQueries = refetchQueries(getResultWithDataState());
|
|
273
|
+
}
|
|
274
274
|
if (cacheWrites.length > 0 ||
|
|
275
|
-
(
|
|
275
|
+
(refetchQueries || "").length > 0 ||
|
|
276
276
|
mutation.update ||
|
|
277
277
|
mutation.onQueryUpdated ||
|
|
278
278
|
mutation.removeOptimistic) {
|
|
@@ -289,8 +289,6 @@ class QueryInfo {
|
|
|
289
289
|
const { update } = mutation;
|
|
290
290
|
// Determine whether result is a SingleExecutionResult,
|
|
291
291
|
// or the final ExecutionPatchResult.
|
|
292
|
-
const isFinalResult = !(0, internal_1.isExecutionPatchResult)(result) ||
|
|
293
|
-
((0, internal_1.isExecutionPatchIncrementalResult)(result) && !result.hasNext);
|
|
294
292
|
if (update) {
|
|
295
293
|
if (!skipCache) {
|
|
296
294
|
// Re-read the ROOT_MUTATION data we just wrote into the cache
|
|
@@ -309,19 +307,14 @@ class QueryInfo {
|
|
|
309
307
|
returnPartialData: true,
|
|
310
308
|
});
|
|
311
309
|
if (diff.complete) {
|
|
312
|
-
result = {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
if ("hasNext" in result) {
|
|
317
|
-
delete result.hasNext;
|
|
318
|
-
}
|
|
310
|
+
result = {
|
|
311
|
+
...result,
|
|
312
|
+
data: diff.result,
|
|
313
|
+
};
|
|
319
314
|
}
|
|
320
315
|
}
|
|
321
|
-
// If we've received the whole response,
|
|
322
|
-
|
|
323
|
-
// call the update function.
|
|
324
|
-
if (isFinalResult) {
|
|
316
|
+
// If we've received the whole response, call the update function.
|
|
317
|
+
if (!this.hasNext) {
|
|
325
318
|
update(cache, result, {
|
|
326
319
|
context: mutation.context,
|
|
327
320
|
variables: mutation.variables,
|
|
@@ -330,7 +323,7 @@ class QueryInfo {
|
|
|
330
323
|
}
|
|
331
324
|
// TODO Do this with cache.evict({ id: 'ROOT_MUTATION' }) but make it
|
|
332
325
|
// shallow to allow rolling back optimistic evictions.
|
|
333
|
-
if (!skipCache && !mutation.keepRootFields &&
|
|
326
|
+
if (!skipCache && !mutation.keepRootFields && !this.hasNext) {
|
|
334
327
|
cache.modify({
|
|
335
328
|
id: "ROOT_MUTATION",
|
|
336
329
|
fields(value, { fieldName, DELETE }) {
|
|
@@ -339,7 +332,7 @@ class QueryInfo {
|
|
|
339
332
|
});
|
|
340
333
|
}
|
|
341
334
|
},
|
|
342
|
-
include:
|
|
335
|
+
include: refetchQueries,
|
|
343
336
|
// Write the final mutation.result to the root layer of the cache.
|
|
344
337
|
optimistic: false,
|
|
345
338
|
// Remove the corresponding optimistic layer at the same time as we
|
|
@@ -393,21 +386,6 @@ class QueryInfo {
|
|
|
393
386
|
}
|
|
394
387
|
}
|
|
395
388
|
exports.QueryInfo = QueryInfo;
|
|
396
|
-
function handleIncrementalResult(result, lastDiff) {
|
|
397
|
-
if ("incremental" in result && (0, internal_1.isNonEmptyArray)(result.incremental)) {
|
|
398
|
-
const mergedData = (0, internal_1.mergeIncrementalData)(lastDiff.result, result);
|
|
399
|
-
result.data = mergedData;
|
|
400
|
-
// Detect the first chunk of a deferred query and merge it with existing
|
|
401
|
-
// cache data. This ensures a `cache-first` fetch policy that returns
|
|
402
|
-
// partial cache data or a `cache-and-network` fetch policy that already
|
|
403
|
-
// has full data in the cache does not complain when trying to merge the
|
|
404
|
-
// initial deferred server data with existing cache data.
|
|
405
|
-
}
|
|
406
|
-
else if ("hasNext" in result && result.hasNext) {
|
|
407
|
-
const merger = new internal_1.DeepMerger();
|
|
408
|
-
result.data = merger.merge(lastDiff.result, result.data);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
389
|
function shouldWriteResult(result, errorPolicy = "none") {
|
|
412
390
|
const ignoreErrors = errorPolicy === "ignore" || errorPolicy === "all";
|
|
413
391
|
let writeWithErrors = !(0, internal_1.graphQLResultHasError)(result);
|