@apollo/client 4.0.0-alpha.4 → 4.0.0-alpha.5
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/.changeset/eleven-kangaroos-jump.md +5 -0
- package/.changeset/forty-shrimps-fry.md +5 -0
- package/.changeset/grumpy-vans-type.md +5 -0
- package/.changeset/little-spoons-kick.md +7 -0
- package/.changeset/loud-cows-raise.md +7 -0
- package/.changeset/many-buses-allow.md +5 -0
- package/.changeset/poor-eels-punch.md +5 -0
- package/.changeset/pre.json +13 -0
- package/.changeset/real-teachers-peel.md +5 -0
- package/.changeset/slimy-chicken-melt.md +5 -0
- package/.changeset/thick-books-grin.md +5 -0
- package/.changeset/tough-rockets-allow.md +5 -0
- package/.changeset/tricky-tables-shave.md +5 -0
- package/.changeset/warm-ties-sit.md +7 -0
- package/CHANGELOG.md +40 -0
- 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/policies.cjs +4 -4
- package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
- package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
- package/__cjs/core/ApolloClient.cjs +3 -3
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +4 -4
- package/__cjs/core/LocalState.cjs +2 -2
- package/__cjs/core/ObservableQuery.cjs +15 -12
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/QueryManager.cjs +57 -35
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +3 -3
- package/__cjs/core/types.d.cts +32 -0
- package/__cjs/invariantErrorCodes.cjs +57 -77
- package/__cjs/link/core/ApolloLink.cjs +2 -2
- package/__cjs/link/http/checkFetcher.cjs +1 -1
- package/__cjs/link/http/createHttpLink.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
- package/__cjs/link/http/serializeFetchParameter.cjs +1 -1
- package/__cjs/link/persisted-queries/index.cjs +2 -2
- package/__cjs/link/utils/validateOperation.cjs +1 -1
- package/__cjs/masking/maskDefinition.cjs +2 -2
- package/__cjs/masking/maskFragment.cjs +2 -2
- package/__cjs/masking/maskOperation.cjs +1 -1
- package/__cjs/masking/utils.cjs +1 -1
- package/__cjs/react/context/ApolloConsumer.cjs +1 -1
- package/__cjs/react/context/ApolloContext.cjs +1 -1
- package/__cjs/react/context/ApolloContext.cjs.map +1 -1
- package/__cjs/react/context/ApolloContext.d.cts +2 -2
- package/__cjs/react/context/ApolloProvider.cjs +1 -1
- package/__cjs/react/hooks/internal/wrapHook.cjs +26 -5
- package/__cjs/react/hooks/internal/wrapHook.cjs.map +1 -1
- package/__cjs/react/hooks/internal/wrapHook.d.cts +3 -1
- package/__cjs/react/hooks/useMutation.cjs +14 -19
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +4 -4
- package/__cjs/react/hooks/useQuery.cjs +82 -187
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +4 -0
- package/__cjs/react/hooks/useSubscription.cjs +8 -57
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +6 -42
- package/__cjs/react/hooks/useSuspenseQuery.cjs +2 -2
- package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
- package/__cjs/react/internal/index.cjs +3 -1
- package/__cjs/react/internal/index.cjs.map +1 -1
- package/__cjs/react/internal/index.d.cts +1 -0
- package/__cjs/react/ssr/getDataFromTree.cjs +43 -12
- package/__cjs/react/ssr/getDataFromTree.cjs.map +1 -1
- package/__cjs/react/ssr/getDataFromTree.d.cts +5 -0
- package/__cjs/react/ssr/index.cjs +1 -3
- package/__cjs/react/ssr/index.cjs.map +1 -1
- package/__cjs/react/ssr/index.d.cts +0 -1
- package/__cjs/react/ssr/useSSRQuery.cjs +60 -0
- package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -0
- package/__cjs/react/ssr/useSSRQuery.d.cts +5 -0
- package/__cjs/react/types/deprecated.d.cts +1 -1
- package/__cjs/react/types/types.documentation.d.cts +4 -12
- package/__cjs/testing/matchers/index.cjs +2 -0
- package/__cjs/testing/matchers/index.cjs.map +1 -1
- package/__cjs/testing/matchers/toEmitStrictTyped.cjs +42 -0
- package/__cjs/testing/matchers/toEmitStrictTyped.cjs.map +1 -0
- package/__cjs/testing/matchers/toEmitStrictTyped.d.cts +7 -0
- package/__cjs/testing/matchers/toEqualStrictTyped.cjs +2 -20
- package/__cjs/testing/matchers/toEqualStrictTyped.cjs.map +1 -1
- package/__cjs/testing/matchers/utils/getSerializableProperties.cjs +23 -0
- package/__cjs/testing/matchers/utils/getSerializableProperties.cjs.map +1 -0
- package/__cjs/testing/matchers/utils/getSerializableProperties.d.cts +2 -0
- package/__cjs/version.cjs +1 -1
- package/__cjs/version.d.cts +1 -1
- 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/policies.js +4 -4
- package/cache/inmemory/readFromStore.js +2 -2
- package/cache/inmemory/writeToStore.js +4 -4
- package/core/ApolloClient.d.ts +4 -4
- package/core/ApolloClient.js +3 -3
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +2 -2
- package/core/ObservableQuery.js +15 -12
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts +3 -3
- package/core/QueryManager.js +58 -36
- package/core/QueryManager.js.map +1 -1
- package/core/types.d.ts +32 -0
- package/invariantErrorCodes.js +57 -77
- package/link/core/ApolloLink.js +2 -2
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/parseAndCheckHttpResponse.js +1 -1
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/utils/validateOperation.js +1 -1
- package/masking/maskDefinition.js +2 -2
- package/masking/maskFragment.js +2 -2
- package/masking/maskOperation.js +1 -1
- package/masking/utils.js +1 -1
- package/package.json +1 -1
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloContext.d.ts +2 -2
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/hooks/internal/wrapHook.d.ts +3 -1
- package/react/hooks/internal/wrapHook.js +24 -5
- package/react/hooks/internal/wrapHook.js.map +1 -1
- package/react/hooks/useMutation.d.ts +4 -4
- package/react/hooks/useMutation.js +14 -19
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +4 -0
- package/react/hooks/useQuery.js +83 -188
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +6 -42
- package/react/hooks/useSubscription.js +7 -53
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/internal/index.d.ts +1 -0
- package/react/internal/index.js +2 -1
- package/react/internal/index.js.map +1 -1
- package/react/ssr/getDataFromTree.d.ts +5 -0
- package/react/ssr/getDataFromTree.js +43 -12
- package/react/ssr/getDataFromTree.js.map +1 -1
- package/react/ssr/index.d.ts +0 -1
- package/react/ssr/index.js +0 -1
- package/react/ssr/index.js.map +1 -1
- package/react/ssr/useSSRQuery.d.ts +5 -0
- package/react/ssr/useSSRQuery.js +56 -0
- package/react/ssr/useSSRQuery.js.map +1 -0
- package/react/types/deprecated.d.ts +1 -1
- package/react/types/types.documentation.d.ts +4 -12
- package/testing/matchers/index.js +2 -0
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toEmitStrictTyped.d.ts +7 -0
- package/testing/matchers/toEmitStrictTyped.js +38 -0
- package/testing/matchers/toEmitStrictTyped.js.map +1 -0
- package/testing/matchers/toEqualStrictTyped.js +1 -19
- package/testing/matchers/toEqualStrictTyped.js.map +1 -1
- package/testing/matchers/utils/getSerializableProperties.d.ts +2 -0
- package/testing/matchers/utils/getSerializableProperties.js +20 -0
- package/testing/matchers/utils/getSerializableProperties.js.map +1 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/__cjs/react/ssr/RenderPromises.cjs +0 -104
- package/__cjs/react/ssr/RenderPromises.cjs.map +0 -1
- package/__cjs/react/ssr/RenderPromises.d.cts +0 -25
- package/react/ssr/RenderPromises.d.ts +0 -25
- package/react/ssr/RenderPromises.js +0 -100
- package/react/ssr/RenderPromises.js.map +0 -1
|
@@ -95,15 +95,15 @@ class QueryManager {
|
|
|
95
95
|
this.queries.forEach((_info, queryId) => {
|
|
96
96
|
this.removeQuery(queryId);
|
|
97
97
|
});
|
|
98
|
-
this.cancelPendingFetches((0, invariant_1.newInvariantError)(
|
|
98
|
+
this.cancelPendingFetches((0, invariant_1.newInvariantError)(68));
|
|
99
99
|
}
|
|
100
100
|
cancelPendingFetches(error) {
|
|
101
101
|
this.fetchCancelFns.forEach((cancel) => cancel(error));
|
|
102
102
|
this.fetchCancelFns.clear();
|
|
103
103
|
}
|
|
104
104
|
async mutate({ mutation, variables, optimisticResponse, updateQueries, refetchQueries = [], awaitRefetchQueries = false, update: updateWithProxyFn, onQueryUpdated, fetchPolicy = this.defaultOptions.mutate?.fetchPolicy || "network-only", errorPolicy = this.defaultOptions.mutate?.errorPolicy || "none", keepRootFields, context, }) {
|
|
105
|
-
(0, invariant_1.invariant)(mutation,
|
|
106
|
-
(0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache",
|
|
105
|
+
(0, invariant_1.invariant)(mutation, 69);
|
|
106
|
+
(0, invariant_1.invariant)(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 70);
|
|
107
107
|
const mutationId = this.generateMutationId();
|
|
108
108
|
mutation = this.cache.transformForLink(this.transform(mutation));
|
|
109
109
|
const { hasClientExports } = this.getDocumentInfo(mutation);
|
|
@@ -137,7 +137,8 @@ class QueryManager {
|
|
|
137
137
|
optimisticResponse: isOptimistic ? optimisticResponse : void 0,
|
|
138
138
|
}, variables, {}, false)
|
|
139
139
|
.pipe((0, rxjs_1.mergeMap)((result) => {
|
|
140
|
-
|
|
140
|
+
const hasErrors = (0, utilities_4.graphQLResultHasError)(result);
|
|
141
|
+
if (hasErrors && errorPolicy === "none") {
|
|
141
142
|
throw new errors_1.CombinedGraphQLErrors((0, utilities_4.getGraphQLErrorsFromResult)(result));
|
|
142
143
|
}
|
|
143
144
|
if (mutationStoreValue) {
|
|
@@ -148,8 +149,7 @@ class QueryManager {
|
|
|
148
149
|
if (typeof refetchQueries === "function") {
|
|
149
150
|
refetchQueries = refetchQueries(storeResult);
|
|
150
151
|
}
|
|
151
|
-
if (errorPolicy === "ignore" &&
|
|
152
|
-
(0, utilities_4.graphQLResultHasError)(storeResult)) {
|
|
152
|
+
if (errorPolicy === "ignore" && hasErrors) {
|
|
153
153
|
delete storeResult.errors;
|
|
154
154
|
}
|
|
155
155
|
return (0, rxjs_1.from)(this.markMutationResult({
|
|
@@ -178,28 +178,40 @@ class QueryManager {
|
|
|
178
178
|
// ExecutionPatchResult has arrived and we have assembled the
|
|
179
179
|
// multipart response into a single result.
|
|
180
180
|
if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
|
|
181
|
-
|
|
182
|
-
...storeResult,
|
|
181
|
+
const result = {
|
|
183
182
|
data: this.maskOperation({
|
|
184
183
|
document: mutation,
|
|
185
184
|
data: storeResult.data,
|
|
186
185
|
fetchPolicy,
|
|
187
186
|
id: mutationId,
|
|
188
187
|
}),
|
|
189
|
-
}
|
|
188
|
+
};
|
|
189
|
+
if ((0, utilities_4.graphQLResultHasError)(storeResult)) {
|
|
190
|
+
result.error = new errors_1.CombinedGraphQLErrors((0, utilities_4.getGraphQLErrorsFromResult)(storeResult));
|
|
191
|
+
}
|
|
192
|
+
if (storeResult.extensions) {
|
|
193
|
+
result.extensions = storeResult.extensions;
|
|
194
|
+
}
|
|
195
|
+
resolve(result);
|
|
190
196
|
}
|
|
191
197
|
},
|
|
192
198
|
error: (err) => {
|
|
193
|
-
|
|
199
|
+
const error = maybeWrapError(err);
|
|
194
200
|
if (mutationStoreValue) {
|
|
195
201
|
mutationStoreValue.loading = false;
|
|
196
|
-
mutationStoreValue.error =
|
|
202
|
+
mutationStoreValue.error = error;
|
|
197
203
|
}
|
|
198
204
|
if (isOptimistic) {
|
|
199
205
|
this.cache.removeOptimistic(mutationId);
|
|
200
206
|
}
|
|
201
207
|
this.broadcastQueries();
|
|
202
|
-
|
|
208
|
+
if (errorPolicy === "ignore") {
|
|
209
|
+
return resolve({ data: undefined });
|
|
210
|
+
}
|
|
211
|
+
if (errorPolicy === "all") {
|
|
212
|
+
return resolve({ data: undefined, error });
|
|
213
|
+
}
|
|
214
|
+
reject(error);
|
|
203
215
|
},
|
|
204
216
|
});
|
|
205
217
|
});
|
|
@@ -472,10 +484,10 @@ class QueryManager {
|
|
|
472
484
|
// TODO: catch `EmptyError` and rethrow as network error if `complete`
|
|
473
485
|
// notification is emitted without a value.
|
|
474
486
|
query(options, queryId = this.generateQueryId()) {
|
|
475
|
-
(0, invariant_1.invariant)(options.query,
|
|
476
|
-
(0, invariant_1.invariant)(options.query.kind === "Document",
|
|
477
|
-
(0, invariant_1.invariant)(!options.returnPartialData,
|
|
478
|
-
(0, invariant_1.invariant)(!options.pollInterval,
|
|
487
|
+
(0, invariant_1.invariant)(options.query, 71);
|
|
488
|
+
(0, invariant_1.invariant)(options.query.kind === "Document", 72);
|
|
489
|
+
(0, invariant_1.invariant)(!options.returnPartialData, 73);
|
|
490
|
+
(0, invariant_1.invariant)(!options.pollInterval, 74);
|
|
479
491
|
const query = this.transform(options.query);
|
|
480
492
|
return this.fetchQuery(queryId, { ...options, query })
|
|
481
493
|
.then((result) => result && {
|
|
@@ -509,7 +521,7 @@ class QueryManager {
|
|
|
509
521
|
// depend on values that previously existed in the data portion of the
|
|
510
522
|
// store. So, we cancel the promises and observers that we have issued
|
|
511
523
|
// so far and not yet resolved (in the case of queries).
|
|
512
|
-
this.cancelPendingFetches((0, invariant_1.newInvariantError)(
|
|
524
|
+
this.cancelPendingFetches((0, invariant_1.newInvariantError)(75));
|
|
513
525
|
this.queries.forEach((queryInfo) => {
|
|
514
526
|
if (queryInfo.observableQuery) {
|
|
515
527
|
// Set loading to true so listeners don't trigger unless they want
|
|
@@ -597,10 +609,10 @@ class QueryManager {
|
|
|
597
609
|
if (!included) {
|
|
598
610
|
const queryName = queryNames.get(nameOrQueryString);
|
|
599
611
|
if (queryName) {
|
|
600
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
612
|
+
__DEV__ && invariant_1.invariant.warn(76, queryName);
|
|
601
613
|
}
|
|
602
614
|
else {
|
|
603
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
615
|
+
__DEV__ && invariant_1.invariant.warn(77);
|
|
604
616
|
}
|
|
605
617
|
}
|
|
606
618
|
});
|
|
@@ -629,38 +641,48 @@ class QueryManager {
|
|
|
629
641
|
const { fetchPolicy, errorPolicy = "none", context = {}, extensions = {}, } = options;
|
|
630
642
|
query = this.transform(query);
|
|
631
643
|
variables = this.getVariables(query, variables);
|
|
632
|
-
const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe((0, rxjs_1.map)((
|
|
644
|
+
const makeObservable = (variables) => this.getObservableFromLink(query, context, variables, extensions).pipe((0, rxjs_1.map)((rawResult) => {
|
|
633
645
|
if (fetchPolicy !== "no-cache") {
|
|
634
646
|
// the subscription interface should handle not sending us results we no longer subscribe to.
|
|
635
647
|
// XXX I don't think we ever send in an object with errors, but we might in the future...
|
|
636
|
-
if ((0, QueryInfo_js_1.shouldWriteResult)(
|
|
648
|
+
if ((0, QueryInfo_js_1.shouldWriteResult)(rawResult, errorPolicy)) {
|
|
637
649
|
this.cache.write({
|
|
638
650
|
query,
|
|
639
|
-
result:
|
|
651
|
+
result: rawResult.data,
|
|
640
652
|
dataId: "ROOT_SUBSCRIPTION",
|
|
641
653
|
variables: variables,
|
|
642
654
|
});
|
|
643
655
|
}
|
|
644
656
|
this.broadcastQueries();
|
|
645
657
|
}
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
658
|
+
const result = {
|
|
659
|
+
data: rawResult.data ?? undefined,
|
|
660
|
+
};
|
|
661
|
+
if ((0, utilities_4.graphQLResultHasError)(rawResult)) {
|
|
662
|
+
result.error = new errors_1.CombinedGraphQLErrors(rawResult.errors);
|
|
663
|
+
}
|
|
664
|
+
else if ((0, errors_1.graphQLResultHasProtocolErrors)(rawResult)) {
|
|
665
|
+
result.error = rawResult.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
|
|
666
|
+
// Don't emit protocol errors added by HttpLink
|
|
667
|
+
delete rawResult.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
|
|
668
|
+
}
|
|
669
|
+
if (rawResult.extensions &&
|
|
670
|
+
Object.keys(rawResult.extensions).length) {
|
|
671
|
+
result.extensions = rawResult.extensions;
|
|
650
672
|
}
|
|
651
|
-
if (
|
|
652
|
-
|
|
653
|
-
// to our documentation, so we throw protocol errors regardless of the
|
|
654
|
-
// set error policy.
|
|
655
|
-
throw result.extensions[errors_2.PROTOCOL_ERRORS_SYMBOL];
|
|
673
|
+
if (result.error && errorPolicy === "none") {
|
|
674
|
+
result.data = undefined;
|
|
656
675
|
}
|
|
657
676
|
if (errorPolicy === "ignore") {
|
|
658
|
-
delete result.
|
|
677
|
+
delete result.error;
|
|
659
678
|
}
|
|
660
679
|
return result;
|
|
661
680
|
}), (0, rxjs_1.catchError)((error) => {
|
|
662
|
-
|
|
663
|
-
|
|
681
|
+
if (errorPolicy === "ignore") {
|
|
682
|
+
return (0, rxjs_1.of)({ data: undefined });
|
|
683
|
+
}
|
|
684
|
+
return (0, rxjs_1.of)({ data: undefined, error: maybeWrapError(error) });
|
|
685
|
+
}), (0, rxjs_1.filter)((result) => !!(result.data || result.error)));
|
|
664
686
|
if (this.getDocumentInfo(query).hasClientExports) {
|
|
665
687
|
const observablePromise = this.localState
|
|
666
688
|
.addExportedVariables(query, variables, context)
|
|
@@ -1031,7 +1053,7 @@ class QueryManager {
|
|
|
1031
1053
|
!(0, utilities_3.isFullyUnmaskedOperation)(document) &&
|
|
1032
1054
|
!this.noCacheWarningsByQueryId.has(operationId)) {
|
|
1033
1055
|
this.noCacheWarningsByQueryId.add(operationId);
|
|
1034
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
1056
|
+
__DEV__ && invariant_1.invariant.warn(78, (0, utilities_4.getOperationName)(document) ??
|
|
1035
1057
|
`Unnamed ${operationType ?? "operation"}`);
|
|
1036
1058
|
}
|
|
1037
1059
|
}
|