@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
|
@@ -33,6 +33,7 @@ class QueryManager {
|
|
|
33
33
|
ssrMode;
|
|
34
34
|
defaultContext;
|
|
35
35
|
dataMasking;
|
|
36
|
+
incrementalHandler;
|
|
36
37
|
localState;
|
|
37
38
|
queryDeduplication;
|
|
38
39
|
/**
|
|
@@ -69,6 +70,7 @@ class QueryManager {
|
|
|
69
70
|
this.assumeImmutableResults = options.assumeImmutableResults;
|
|
70
71
|
this.dataMasking = options.dataMasking;
|
|
71
72
|
this.localState = options.localState;
|
|
73
|
+
this.incrementalHandler = options.incrementalHandler;
|
|
72
74
|
const documentTransform = options.documentTransform;
|
|
73
75
|
this.documentTransform =
|
|
74
76
|
documentTransform ?
|
|
@@ -97,7 +99,7 @@ class QueryManager {
|
|
|
97
99
|
*/
|
|
98
100
|
stop() {
|
|
99
101
|
this.obsQueries.forEach((oq) => oq.stop());
|
|
100
|
-
this.cancelPendingFetches((0, invariant_1.newInvariantError)(
|
|
102
|
+
this.cancelPendingFetches((0, invariant_1.newInvariantError)(85));
|
|
101
103
|
}
|
|
102
104
|
cancelPendingFetches(error) {
|
|
103
105
|
this.fetchCancelFns.forEach((cancel) => cancel(error));
|
|
@@ -112,7 +114,7 @@ class QueryManager {
|
|
|
112
114
|
if (environment_1.__DEV__) {
|
|
113
115
|
(0, invariant_1.invariant)(
|
|
114
116
|
this.localState,
|
|
115
|
-
|
|
117
|
+
86,
|
|
116
118
|
(0, internal_1.getOperationName)(mutation, "(anonymous)")
|
|
117
119
|
);
|
|
118
120
|
}
|
|
@@ -151,21 +153,7 @@ class QueryManager {
|
|
|
151
153
|
optimisticResponse: isOptimistic ? optimisticResponse : void 0,
|
|
152
154
|
}, variables, {}, false)
|
|
153
155
|
.observable.pipe(validateDidEmitValue(), (0, rxjs_2.mergeMap)((result) => {
|
|
154
|
-
const hasErrors = (0, internal_1.graphQLResultHasError)(result);
|
|
155
|
-
if (hasErrors && errorPolicy === "none") {
|
|
156
|
-
throw new errors_1.CombinedGraphQLErrors(result);
|
|
157
|
-
}
|
|
158
|
-
if (mutationStoreValue) {
|
|
159
|
-
mutationStoreValue.loading = false;
|
|
160
|
-
mutationStoreValue.error = null;
|
|
161
|
-
}
|
|
162
156
|
const storeResult = { ...result };
|
|
163
|
-
if (typeof refetchQueries === "function") {
|
|
164
|
-
refetchQueries = refetchQueries(storeResult);
|
|
165
|
-
}
|
|
166
|
-
if (errorPolicy === "ignore" && hasErrors) {
|
|
167
|
-
delete storeResult.errors;
|
|
168
|
-
}
|
|
169
157
|
return (0, rxjs_2.from)(queryInfo.markMutationResult(storeResult, {
|
|
170
158
|
document: mutation,
|
|
171
159
|
variables,
|
|
@@ -182,6 +170,17 @@ class QueryManager {
|
|
|
182
170
|
onQueryUpdated,
|
|
183
171
|
keepRootFields,
|
|
184
172
|
}));
|
|
173
|
+
}))
|
|
174
|
+
.pipe((0, rxjs_2.map)((storeResult) => {
|
|
175
|
+
const hasErrors = (0, internal_1.graphQLResultHasError)(storeResult);
|
|
176
|
+
if (hasErrors && errorPolicy === "none") {
|
|
177
|
+
throw new errors_1.CombinedGraphQLErrors(storeResult);
|
|
178
|
+
}
|
|
179
|
+
if (mutationStoreValue) {
|
|
180
|
+
mutationStoreValue.loading = false;
|
|
181
|
+
mutationStoreValue.error = null;
|
|
182
|
+
}
|
|
183
|
+
return storeResult;
|
|
185
184
|
}))
|
|
186
185
|
.subscribe({
|
|
187
186
|
next: (storeResult) => {
|
|
@@ -191,7 +190,7 @@ class QueryManager {
|
|
|
191
190
|
// we resolve with a SingleExecutionResult or after the final
|
|
192
191
|
// ExecutionPatchResult has arrived and we have assembled the
|
|
193
192
|
// multipart response into a single result.
|
|
194
|
-
if (!
|
|
193
|
+
if (!queryInfo.hasNext) {
|
|
195
194
|
const result = {
|
|
196
195
|
data: this.maskOperation({
|
|
197
196
|
document: mutation,
|
|
@@ -203,7 +202,7 @@ class QueryManager {
|
|
|
203
202
|
if ((0, internal_1.graphQLResultHasError)(storeResult)) {
|
|
204
203
|
result.error = new errors_1.CombinedGraphQLErrors(storeResult);
|
|
205
204
|
}
|
|
206
|
-
if (storeResult.extensions) {
|
|
205
|
+
if (Object.keys(storeResult.extensions || {}).length) {
|
|
207
206
|
result.extensions = storeResult.extensions;
|
|
208
207
|
}
|
|
209
208
|
resolve(result);
|
|
@@ -268,6 +267,7 @@ class QueryManager {
|
|
|
268
267
|
hasClientExports: (0, internal_1.hasDirectives)(["client", "export"], document, true),
|
|
269
268
|
hasForcedResolvers: (0, internal_1.hasForcedResolvers)(document),
|
|
270
269
|
hasNonreactiveDirective: (0, internal_1.hasDirectives)(["nonreactive"], document),
|
|
270
|
+
hasIncrementalDirective: (0, internal_1.hasDirectives)(["defer"], document),
|
|
271
271
|
nonReactiveQuery: addNonReactiveToNamedFragments(document),
|
|
272
272
|
clientQuery: (0, internal_1.hasDirectives)(["client"], document) ? document : null,
|
|
273
273
|
serverQuery: (0, internal_1.removeDirectivesFromDocument)([
|
|
@@ -353,7 +353,7 @@ class QueryManager {
|
|
|
353
353
|
// depend on values that previously existed in the data portion of the
|
|
354
354
|
// store. So, we cancel the promises and observers that we have issued
|
|
355
355
|
// so far and not yet resolved (in the case of queries).
|
|
356
|
-
this.cancelPendingFetches((0, invariant_1.newInvariantError)(
|
|
356
|
+
this.cancelPendingFetches((0, invariant_1.newInvariantError)(87));
|
|
357
357
|
this.obsQueries.forEach((observableQuery) => {
|
|
358
358
|
// Set loading to true so listeners don't trigger unless they want
|
|
359
359
|
// results with partial data.
|
|
@@ -423,10 +423,10 @@ class QueryManager {
|
|
|
423
423
|
if (!included) {
|
|
424
424
|
const queryName = queryNames.get(nameOrQueryString);
|
|
425
425
|
if (queryName) {
|
|
426
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
426
|
+
__DEV__ && invariant_1.invariant.warn(88, queryName);
|
|
427
427
|
}
|
|
428
428
|
else {
|
|
429
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
429
|
+
__DEV__ && invariant_1.invariant.warn(89);
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
432
|
});
|
|
@@ -437,8 +437,8 @@ class QueryManager {
|
|
|
437
437
|
const observableQueryPromises = [];
|
|
438
438
|
this.getObservableQueries(includeStandby ? "all" : "active").forEach((observableQuery) => {
|
|
439
439
|
const { fetchPolicy } = observableQuery.options;
|
|
440
|
-
if (includeStandby ||
|
|
441
|
-
|
|
440
|
+
if ((includeStandby || fetchPolicy !== "standby") &&
|
|
441
|
+
fetchPolicy !== "cache-only") {
|
|
442
442
|
observableQueryPromises.push(observableQuery.refetch());
|
|
443
443
|
}
|
|
444
444
|
});
|
|
@@ -455,7 +455,7 @@ class QueryManager {
|
|
|
455
455
|
if (environment_1.__DEV__) {
|
|
456
456
|
(0, invariant_1.invariant)(
|
|
457
457
|
!this.getDocumentInfo(query).hasClientExports || this.localState,
|
|
458
|
-
|
|
458
|
+
90,
|
|
459
459
|
(0, internal_1.getOperationName)(query, "(anonymous)")
|
|
460
460
|
);
|
|
461
461
|
}
|
|
@@ -523,81 +523,92 @@ class QueryManager {
|
|
|
523
523
|
deduplication = context?.queryDeduplication ??
|
|
524
524
|
this.queryDeduplication) {
|
|
525
525
|
let entry = {};
|
|
526
|
-
const { serverQuery, clientQuery, operationType } = this.getDocumentInfo(query);
|
|
526
|
+
const { serverQuery, clientQuery, operationType, hasIncrementalDirective } = this.getDocumentInfo(query);
|
|
527
527
|
const operationName = (0, internal_1.getOperationName)(query);
|
|
528
528
|
const executeContext = {
|
|
529
529
|
client: this.client,
|
|
530
530
|
};
|
|
531
531
|
if (serverQuery) {
|
|
532
532
|
const { inFlightLinkObservables, link } = this;
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
context = operation.context;
|
|
545
|
-
function withRestart(source) {
|
|
546
|
-
return new rxjs_1.Observable((observer) => {
|
|
547
|
-
function subscribe() {
|
|
548
|
-
return source.subscribe({
|
|
549
|
-
next: observer.next.bind(observer),
|
|
550
|
-
complete: observer.complete.bind(observer),
|
|
551
|
-
error: observer.error.bind(observer),
|
|
552
|
-
});
|
|
553
|
-
}
|
|
554
|
-
let subscription = subscribe();
|
|
555
|
-
entry.restart ||= () => {
|
|
556
|
-
subscription.unsubscribe();
|
|
557
|
-
subscription = subscribe();
|
|
558
|
-
};
|
|
559
|
-
return () => {
|
|
560
|
-
subscription.unsubscribe();
|
|
561
|
-
entry.restart = undefined;
|
|
562
|
-
};
|
|
533
|
+
try {
|
|
534
|
+
const operation = this.incrementalHandler.prepareRequest({
|
|
535
|
+
query: serverQuery,
|
|
536
|
+
variables,
|
|
537
|
+
operationName,
|
|
538
|
+
context: {
|
|
539
|
+
...this.defaultContext,
|
|
540
|
+
...context,
|
|
541
|
+
queryDeduplication: deduplication,
|
|
542
|
+
},
|
|
543
|
+
extensions,
|
|
563
544
|
});
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
inFlightLinkObservables.remove(printedServerQuery, varJson);
|
|
545
|
+
context = operation.context;
|
|
546
|
+
function withRestart(source) {
|
|
547
|
+
return new rxjs_1.Observable((observer) => {
|
|
548
|
+
function subscribe() {
|
|
549
|
+
return source.subscribe({
|
|
550
|
+
next: observer.next.bind(observer),
|
|
551
|
+
complete: observer.complete.bind(observer),
|
|
552
|
+
error: observer.error.bind(observer),
|
|
553
|
+
});
|
|
574
554
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
555
|
+
let subscription = subscribe();
|
|
556
|
+
entry.restart ||= () => {
|
|
557
|
+
subscription.unsubscribe();
|
|
558
|
+
subscription = subscribe();
|
|
559
|
+
};
|
|
560
|
+
return () => {
|
|
561
|
+
subscription.unsubscribe();
|
|
562
|
+
entry.restart = undefined;
|
|
563
|
+
};
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
if (deduplication) {
|
|
567
|
+
const printedServerQuery = (0, utilities_1.print)(serverQuery);
|
|
568
|
+
const varJson = (0, cache_1.canonicalStringify)(variables);
|
|
569
|
+
entry = inFlightLinkObservables.lookup(printedServerQuery, varJson);
|
|
570
|
+
if (!entry.observable) {
|
|
571
|
+
entry.observable = (0, link_1.execute)(link, operation, executeContext).pipe(withRestart, (0, rxjs_2.finalize)(() => {
|
|
572
|
+
if (inFlightLinkObservables.peek(printedServerQuery, varJson) ===
|
|
573
|
+
entry) {
|
|
574
|
+
inFlightLinkObservables.remove(printedServerQuery, varJson);
|
|
575
|
+
}
|
|
576
|
+
}),
|
|
577
|
+
// We don't want to replay the last emitted value for
|
|
578
|
+
// subscriptions and instead opt to wait to receive updates until
|
|
579
|
+
// the subscription emits new values.
|
|
580
|
+
operationType === graphql_1.OperationTypeNode.SUBSCRIPTION ?
|
|
581
|
+
(0, rxjs_2.share)()
|
|
582
|
+
: (0, rxjs_2.shareReplay)({ refCount: true }));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
entry.observable = (0, link_1.execute)(link, operation, executeContext).pipe(withRestart);
|
|
582
587
|
}
|
|
583
588
|
}
|
|
584
|
-
|
|
585
|
-
entry.observable = (0,
|
|
589
|
+
catch (error) {
|
|
590
|
+
entry.observable = (0, rxjs_1.throwError)(() => error);
|
|
586
591
|
}
|
|
587
592
|
}
|
|
588
593
|
else {
|
|
589
594
|
entry.observable = (0, rxjs_2.of)({ data: {} });
|
|
590
595
|
}
|
|
591
596
|
if (clientQuery) {
|
|
597
|
+
const { operation } = (0, internal_1.getOperationDefinition)(query);
|
|
592
598
|
if (environment_1.__DEV__) {
|
|
593
|
-
const { operation } = (0, internal_1.getOperationDefinition)(query);
|
|
594
599
|
(0, invariant_1.invariant)(
|
|
595
600
|
this.localState,
|
|
596
|
-
|
|
601
|
+
91,
|
|
597
602
|
operation[0].toUpperCase() + operation.slice(1),
|
|
598
603
|
operationName ?? "(anonymous)"
|
|
599
604
|
);
|
|
600
605
|
}
|
|
606
|
+
(0, invariant_1.invariant)(
|
|
607
|
+
!hasIncrementalDirective,
|
|
608
|
+
92,
|
|
609
|
+
operation[0].toUpperCase() + operation.slice(1),
|
|
610
|
+
operationName ?? "(anonymous)"
|
|
611
|
+
);
|
|
601
612
|
entry.observable = entry.observable.pipe((0, rxjs_2.mergeMap)((result) => {
|
|
602
613
|
return (0, rxjs_2.from)(this.localState.execute({
|
|
603
614
|
client: this.client,
|
|
@@ -624,30 +635,24 @@ class QueryManager {
|
|
|
624
635
|
// missing fragment definitions (for example) before sending this document
|
|
625
636
|
// through the link chain.
|
|
626
637
|
const linkDocument = this.cache.transformForLink(options.query);
|
|
627
|
-
return this.getObservableFromLink(linkDocument, options.context, options.variables).observable.pipe((0, rxjs_2.map)((
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
//
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
// ones used to obtain it from the link.
|
|
642
|
-
queryInfo.markQueryResult(result, {
|
|
643
|
-
...options,
|
|
644
|
-
document: linkDocument,
|
|
645
|
-
cacheWriteBehavior,
|
|
646
|
-
});
|
|
638
|
+
return this.getObservableFromLink(linkDocument, options.context, options.variables).observable.pipe((0, rxjs_2.map)((incoming) => {
|
|
639
|
+
// Use linkDocument rather than queryInfo.document so the
|
|
640
|
+
// operation/fragments used to write the result are the same as the
|
|
641
|
+
// ones used to obtain it from the link.
|
|
642
|
+
const result = queryInfo.markQueryResult(incoming, {
|
|
643
|
+
...options,
|
|
644
|
+
document: linkDocument,
|
|
645
|
+
cacheWriteBehavior,
|
|
646
|
+
});
|
|
647
|
+
const hasErrors = (0, internal_1.graphQLResultHasError)(result);
|
|
648
|
+
if (hasErrors && errorPolicy === "none") {
|
|
649
|
+
queryInfo.resetLastWrite();
|
|
650
|
+
observableQuery?.["resetNotifications"]();
|
|
651
|
+
throw new errors_1.CombinedGraphQLErrors(result);
|
|
647
652
|
}
|
|
648
653
|
const aqr = {
|
|
649
654
|
data: result.data,
|
|
650
|
-
...(
|
|
655
|
+
...(queryInfo.hasNext ?
|
|
651
656
|
{
|
|
652
657
|
loading: true,
|
|
653
658
|
networkStatus: networkStatus_js_1.NetworkStatus.streaming,
|
|
@@ -665,15 +670,16 @@ class QueryManager {
|
|
|
665
670
|
// want to ensure we properly set `data` if we're reporting on an old
|
|
666
671
|
// result which will not be caught by the conditional above that ends up
|
|
667
672
|
// throwing the markError result.
|
|
668
|
-
if (hasErrors
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
673
|
+
if (hasErrors) {
|
|
674
|
+
if (errorPolicy === "none") {
|
|
675
|
+
aqr.data = void 0;
|
|
676
|
+
aqr.dataState = "empty";
|
|
677
|
+
}
|
|
678
|
+
if (errorPolicy !== "ignore") {
|
|
679
|
+
aqr.error = new errors_1.CombinedGraphQLErrors(result);
|
|
680
|
+
if (aqr.dataState !== "streaming") {
|
|
681
|
+
aqr.networkStatus = networkStatus_js_1.NetworkStatus.error;
|
|
682
|
+
}
|
|
677
683
|
}
|
|
678
684
|
}
|
|
679
685
|
return aqr;
|
|
@@ -768,7 +774,7 @@ class QueryManager {
|
|
|
768
774
|
if (environment_1.__DEV__) {
|
|
769
775
|
(0, invariant_1.invariant)(
|
|
770
776
|
this.localState,
|
|
771
|
-
|
|
777
|
+
93,
|
|
772
778
|
(0, internal_1.getOperationName)(normalized.query, "(anonymous)")
|
|
773
779
|
);
|
|
774
780
|
}
|
|
@@ -805,6 +811,9 @@ class QueryManager {
|
|
|
805
811
|
const includedQueriesByOq = new Map();
|
|
806
812
|
if (include) {
|
|
807
813
|
this.getObservableQueries(include).forEach((oq) => {
|
|
814
|
+
if (oq.options.fetchPolicy === "cache-only") {
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
808
817
|
const current = oq.getCurrentResult();
|
|
809
818
|
includedQueriesByOq.set(oq, {
|
|
810
819
|
oq,
|
|
@@ -884,7 +893,8 @@ class QueryManager {
|
|
|
884
893
|
// onQueryUpdated returns false.
|
|
885
894
|
return result;
|
|
886
895
|
}
|
|
887
|
-
if (onQueryUpdated !== null
|
|
896
|
+
if (onQueryUpdated !== null &&
|
|
897
|
+
oq.options.fetchPolicy !== "cache-only") {
|
|
888
898
|
// If we don't have an onQueryUpdated function, and onQueryUpdated
|
|
889
899
|
// was not disabled by passing null, make sure this query is
|
|
890
900
|
// "included" like any other options.include-specified query.
|
|
@@ -940,7 +950,7 @@ class QueryManager {
|
|
|
940
950
|
!this.noCacheWarningsByCause.has(cause)) {
|
|
941
951
|
this.noCacheWarningsByCause.add(cause);
|
|
942
952
|
__DEV__ && invariant_1.invariant.warn(
|
|
943
|
-
|
|
953
|
+
94,
|
|
944
954
|
(0, internal_1.getOperationName)(document, `Unnamed ${operationType ?? "operation"}`)
|
|
945
955
|
);
|
|
946
956
|
}
|
|
@@ -1002,7 +1012,7 @@ class QueryManager {
|
|
|
1002
1012
|
if (environment_1.__DEV__) {
|
|
1003
1013
|
(0, invariant_1.invariant)(
|
|
1004
1014
|
this.localState,
|
|
1005
|
-
|
|
1015
|
+
95,
|
|
1006
1016
|
(0, internal_1.getOperationName)(query, "(anonymous)")
|
|
1007
1017
|
);
|
|
1008
1018
|
}
|
|
@@ -1096,7 +1106,7 @@ function validateDidEmitValue() {
|
|
|
1096
1106
|
didEmitValue = true;
|
|
1097
1107
|
},
|
|
1098
1108
|
complete() {
|
|
1099
|
-
(0, invariant_1.invariant)(didEmitValue,
|
|
1109
|
+
(0, invariant_1.invariant)(didEmitValue, 96);
|
|
1100
1110
|
},
|
|
1101
1111
|
});
|
|
1102
1112
|
}
|