@apollo/client 4.0.0-alpha.20 → 4.0.0-alpha.21
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 +10 -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/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 +10 -10
- package/__cjs/core/ObservableQuery.cjs +15 -11
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +1 -2
- package/__cjs/core/QueryInfo.cjs +223 -34
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +34 -24
- package/__cjs/core/QueryManager.cjs +75 -256
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +4 -36
- package/__cjs/core/networkStatus.cjs +7 -1
- package/__cjs/core/networkStatus.cjs.map +1 -1
- package/__cjs/core/networkStatus.d.cts +7 -1
- package/__cjs/invariantErrorCodes.cjs +64 -69
- 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/local-state/LocalState.cjs +10 -10
- package/__cjs/masking/maskDefinition.cjs.map +1 -1
- package/__cjs/masking/maskFragment.cjs +0 -8
- package/__cjs/masking/maskFragment.cjs.map +1 -1
- package/__cjs/masking/maskOperation.cjs +0 -8
- package/__cjs/masking/maskOperation.cjs.map +1 -1
- package/__cjs/masking/utils.cjs +3 -11
- package/__cjs/masking/utils.cjs.map +1 -1
- package/__cjs/masking/utils.d.cts +0 -1
- package/__cjs/react/hooks/useLazyQuery.cjs +1 -2
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +0 -8
- package/__cjs/utilities/index.cjs +1 -16
- package/__cjs/utilities/index.cjs.map +1 -1
- package/__cjs/utilities/index.d.cts +0 -13
- package/__cjs/version.cjs +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/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +2 -2
- package/cache/inmemory/writeToStore.js +4 -4
- package/core/ApolloClient.js +10 -10
- package/core/ObservableQuery.d.ts +1 -2
- package/core/ObservableQuery.js +15 -11
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +34 -24
- package/core/QueryInfo.js +221 -34
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +4 -36
- package/core/QueryManager.js +77 -258
- package/core/QueryManager.js.map +1 -1
- package/core/networkStatus.d.ts +7 -1
- package/core/networkStatus.js +7 -1
- package/core/networkStatus.js.map +1 -1
- package/invariantErrorCodes.js +64 -69
- 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/local-state/LocalState.js +10 -10
- package/masking/maskDefinition.js.map +1 -1
- package/masking/maskFragment.js +0 -8
- package/masking/maskFragment.js.map +1 -1
- package/masking/maskOperation.js +0 -8
- package/masking/maskOperation.js.map +1 -1
- package/masking/utils.d.ts +0 -1
- package/masking/utils.js +3 -10
- package/masking/utils.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/useLazyQuery.d.ts +0 -8
- package/react/hooks/useLazyQuery.js +1 -2
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/utilities/index.d.ts +0 -13
- package/utilities/index.js +0 -12
- package/utilities/index.js.map +1 -1
- package/version.js +1 -1
|
@@ -195,7 +195,7 @@ export class StoreReader {
|
|
|
195
195
|
else {
|
|
196
196
|
const fragment = getFragmentFromSelection(selection, context.lookupFragment);
|
|
197
197
|
if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
|
|
198
|
-
throw newInvariantError(
|
|
198
|
+
throw newInvariantError(102, selection.name.value);
|
|
199
199
|
}
|
|
200
200
|
if (fragment && policies.fragmentMatches(fragment, typename)) {
|
|
201
201
|
fragment.selectionSet.selections.forEach(workSet.add, workSet);
|
|
@@ -278,7 +278,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
278
278
|
if (isNonNullObject(value)) {
|
|
279
279
|
invariant(
|
|
280
280
|
!isReference(value),
|
|
281
|
-
|
|
281
|
+
103,
|
|
282
282
|
getTypenameFromStoreObject(store, value),
|
|
283
283
|
field.name.value
|
|
284
284
|
);
|
|
@@ -66,7 +66,7 @@ export class StoreWriter {
|
|
|
66
66
|
context,
|
|
67
67
|
});
|
|
68
68
|
if (!isReference(ref)) {
|
|
69
|
-
throw newInvariantError(
|
|
69
|
+
throw newInvariantError(104, result);
|
|
70
70
|
}
|
|
71
71
|
// So far, the store has not been modified, so now it's time to process
|
|
72
72
|
// context.incomingById and merge those incoming fields into context.store.
|
|
@@ -216,7 +216,7 @@ export class StoreWriter {
|
|
|
216
216
|
// provide a default value, so its absence from the written data should
|
|
217
217
|
// not be cause for alarm.
|
|
218
218
|
!policies.getReadFunction(typename, field.name.value)) {
|
|
219
|
-
__DEV__ && invariant.error(
|
|
219
|
+
__DEV__ && invariant.error(105, resultKeyNameFromField(field), result);
|
|
220
220
|
}
|
|
221
221
|
});
|
|
222
222
|
// Identify the result object, even if dataId was already provided,
|
|
@@ -363,7 +363,7 @@ export class StoreWriter {
|
|
|
363
363
|
else {
|
|
364
364
|
const fragment = getFragmentFromSelection(selection, context.lookupFragment);
|
|
365
365
|
if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
|
|
366
|
-
throw newInvariantError(
|
|
366
|
+
throw newInvariantError(106, selection.name.value);
|
|
367
367
|
}
|
|
368
368
|
if (fragment &&
|
|
369
369
|
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
@@ -535,7 +535,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
535
535
|
}
|
|
536
536
|
});
|
|
537
537
|
}
|
|
538
|
-
__DEV__ && invariant.warn(
|
|
538
|
+
__DEV__ && invariant.warn(107, fieldName, parentType, childTypenames.length ?
|
|
539
539
|
"either ensure all objects of type " +
|
|
540
540
|
childTypenames.join(" and ") +
|
|
541
541
|
" have an ID or a custom merge function, or "
|
package/core/ApolloClient.js
CHANGED
|
@@ -69,8 +69,8 @@ export class ApolloClient {
|
|
|
69
69
|
*/
|
|
70
70
|
constructor(options) {
|
|
71
71
|
if (__DEV__) {
|
|
72
|
-
invariant(options.cache,
|
|
73
|
-
invariant(options.link,
|
|
72
|
+
invariant(options.cache, 66);
|
|
73
|
+
invariant(options.link, 67);
|
|
74
74
|
}
|
|
75
75
|
const { cache, documentTransform, ssrMode = false, ssrForceFetchDelay = 0,
|
|
76
76
|
// Expose the client instance as window.__APOLLO_CLIENT__ and call
|
|
@@ -232,13 +232,13 @@ export class ApolloClient {
|
|
|
232
232
|
options = mergeOptions(this.defaultOptions.query, options);
|
|
233
233
|
}
|
|
234
234
|
if (__DEV__) {
|
|
235
|
-
invariant(options.fetchPolicy !== "cache-and-network",
|
|
236
|
-
invariant(options.fetchPolicy !== "standby",
|
|
237
|
-
invariant(options.query,
|
|
238
|
-
invariant(options.query.kind === "Document",
|
|
239
|
-
invariant(!options.returnPartialData,
|
|
240
|
-
invariant(!options.pollInterval,
|
|
241
|
-
invariant(!options.notifyOnNetworkStatusChange,
|
|
235
|
+
invariant(options.fetchPolicy !== "cache-and-network", 68);
|
|
236
|
+
invariant(options.fetchPolicy !== "standby", 69);
|
|
237
|
+
invariant(options.query, 70);
|
|
238
|
+
invariant(options.query.kind === "Document", 71);
|
|
239
|
+
invariant(!options.returnPartialData, 72);
|
|
240
|
+
invariant(!options.pollInterval, 73);
|
|
241
|
+
invariant(!options.notifyOnNetworkStatusChange, 74);
|
|
242
242
|
checkDocument(options.query, OperationTypeNode.QUERY);
|
|
243
243
|
}
|
|
244
244
|
return this.queryManager.query(options);
|
|
@@ -462,7 +462,7 @@ export class ApolloClient {
|
|
|
462
462
|
// result.queries and result.results instead, you shouldn't have to worry
|
|
463
463
|
// about preventing uncaught rejections for the Promise.all result.
|
|
464
464
|
result.catch((error) => {
|
|
465
|
-
__DEV__ && invariant.debug(
|
|
465
|
+
__DEV__ && invariant.debug(75, error);
|
|
466
466
|
});
|
|
467
467
|
return result;
|
|
468
468
|
}
|
|
@@ -4,7 +4,6 @@ import { Observable } from "rxjs";
|
|
|
4
4
|
import type { Cache, MissingFieldError } from "@apollo/client/cache";
|
|
5
5
|
import type { MissingTree } from "@apollo/client/cache";
|
|
6
6
|
import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
|
|
7
|
-
import type { LastWrite } from "./QueryInfo.js";
|
|
8
7
|
import type { QueryManager } from "./QueryManager.js";
|
|
9
8
|
import type { ApolloQueryResult, DefaultContext, OperationVariables, QueryResult, TypedDocumentNode } from "./types.js";
|
|
10
9
|
import type { ErrorPolicy, FetchMoreQueryOptions, NextFetchPolicyContext, RefetchWritePolicy, SubscribeToMoreOptions, UpdateQueryMapFn, WatchQueryFetchPolicy, WatchQueryOptions } from "./watchQueryOptions.js";
|
|
@@ -177,7 +176,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
177
176
|
*
|
|
178
177
|
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
179
178
|
*/
|
|
180
|
-
_lastWrite?:
|
|
179
|
+
_lastWrite?: unknown;
|
|
181
180
|
get query(): TypedDocumentNode<TData, TVariables>;
|
|
182
181
|
/**
|
|
183
182
|
* An object containing the variables that were provided for the query.
|
package/core/ObservableQuery.js
CHANGED
|
@@ -5,7 +5,6 @@ import { compact, filterMap, getOperationDefinition, getQueryDefinition, prevent
|
|
|
5
5
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
6
6
|
import { equalByQuery } from "./equalByQuery.js";
|
|
7
7
|
import { isNetworkRequestInFlight, NetworkStatus } from "./networkStatus.js";
|
|
8
|
-
import { QueryInfo } from "./QueryInfo.js";
|
|
9
8
|
const { assign, hasOwnProperty } = Object;
|
|
10
9
|
const uninitialized = {
|
|
11
10
|
loading: true,
|
|
@@ -346,7 +345,7 @@ export class ObservableQuery {
|
|
|
346
345
|
const queryDef = getQueryDefinition(this.query);
|
|
347
346
|
const vars = queryDef.variableDefinitions;
|
|
348
347
|
if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
|
|
349
|
-
__DEV__ && invariant.warn(
|
|
348
|
+
__DEV__ && invariant.warn(76, variables, queryDef.name?.value || queryDef);
|
|
350
349
|
}
|
|
351
350
|
}
|
|
352
351
|
if (variables && !equal(this.variables, variables)) {
|
|
@@ -395,7 +394,7 @@ export class ObservableQuery {
|
|
|
395
394
|
const updateQuery = fetchMoreOptions?.updateQuery;
|
|
396
395
|
const isCached = this.options.fetchPolicy !== "no-cache";
|
|
397
396
|
if (!isCached) {
|
|
398
|
-
invariant(updateQuery,
|
|
397
|
+
invariant(updateQuery, 77);
|
|
399
398
|
}
|
|
400
399
|
const { finalize, pushNotification } = this.pushOperation(NetworkStatus.fetchMore);
|
|
401
400
|
pushNotification({
|
|
@@ -528,7 +527,7 @@ export class ObservableQuery {
|
|
|
528
527
|
onError(error);
|
|
529
528
|
}
|
|
530
529
|
else {
|
|
531
|
-
__DEV__ && invariant.error(
|
|
530
|
+
__DEV__ && invariant.error(78, error);
|
|
532
531
|
}
|
|
533
532
|
return;
|
|
534
533
|
}
|
|
@@ -667,10 +666,6 @@ export class ObservableQuery {
|
|
|
667
666
|
// TODO Make sure we update the networkStatus (and infer fetchVariables)
|
|
668
667
|
// before actually committing to the fetch.
|
|
669
668
|
const initialFetchPolicy = this.options.fetchPolicy;
|
|
670
|
-
const queryInfo = new QueryInfo({
|
|
671
|
-
queryManager: this.queryManager,
|
|
672
|
-
observableQuery: this,
|
|
673
|
-
});
|
|
674
669
|
options.context ??= {};
|
|
675
670
|
let synchronouslyEmitted = false;
|
|
676
671
|
const onCacheHit = () => {
|
|
@@ -716,7 +711,13 @@ export class ObservableQuery {
|
|
|
716
711
|
}
|
|
717
712
|
}
|
|
718
713
|
});
|
|
719
|
-
let { observable, fromLink } = this.queryManager.fetchObservableWithInfo(
|
|
714
|
+
let { observable, fromLink } = this.queryManager.fetchObservableWithInfo(options, {
|
|
715
|
+
networkStatus,
|
|
716
|
+
query: fetchQuery,
|
|
717
|
+
onCacheHit,
|
|
718
|
+
fetchQueryOperator,
|
|
719
|
+
observableQuery: this,
|
|
720
|
+
});
|
|
720
721
|
// track query and variables from the start of the operation
|
|
721
722
|
const { query, variables } = this;
|
|
722
723
|
const operation = {
|
|
@@ -772,7 +773,7 @@ export class ObservableQuery {
|
|
|
772
773
|
if (pollingInfo && pollingInfo.interval === pollInterval) {
|
|
773
774
|
return;
|
|
774
775
|
}
|
|
775
|
-
invariant(pollInterval,
|
|
776
|
+
invariant(pollInterval, 79);
|
|
776
777
|
const info = pollingInfo || (this.pollingInfo = {});
|
|
777
778
|
info.interval = pollInterval;
|
|
778
779
|
const maybeFetch = () => {
|
|
@@ -1108,6 +1109,9 @@ export class ObservableQuery {
|
|
|
1108
1109
|
};
|
|
1109
1110
|
}
|
|
1110
1111
|
calculateNetworkStatus(baseNetworkStatus) {
|
|
1112
|
+
if (baseNetworkStatus === NetworkStatus.streaming) {
|
|
1113
|
+
return baseNetworkStatus;
|
|
1114
|
+
}
|
|
1111
1115
|
// in the future, this could be more complex logic, e.g. "refetch" and
|
|
1112
1116
|
// "fetchMore" having priority over "polling" or "loading" network statuses
|
|
1113
1117
|
// as for now we just take the "latest" operation that is still active,
|
|
@@ -1255,7 +1259,7 @@ export class ObservableQuery {
|
|
|
1255
1259
|
}
|
|
1256
1260
|
export function logMissingFieldErrors(missing) {
|
|
1257
1261
|
if (__DEV__ && missing) {
|
|
1258
|
-
__DEV__ && invariant.debug(
|
|
1262
|
+
__DEV__ && invariant.debug(80, missing);
|
|
1259
1263
|
}
|
|
1260
1264
|
}
|
|
1261
1265
|
function isEqualQuery(a, b) {
|