@apollo/client 3.12.0-alpha.0 → 3.12.0-rc.0
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/cold-apes-bow.md +5 -0
- package/.changeset/early-bobcats-eat.md +5 -0
- package/.changeset/flat-beans-knock.md +15 -0
- package/.changeset/kind-toys-tie.md +5 -0
- package/.changeset/nervous-owls-hear.md +5 -0
- package/.changeset/pre.json +7 -2
- package/CHANGELOG.md +34 -0
- package/apollo-client.cjs +133 -77
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +30 -20
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +30 -20
- package/cache/inmemory/policies.js +12 -9
- package/cache/inmemory/policies.js.map +1 -1
- package/config/jest/setup.js +5 -0
- package/config/jest/setup.js.map +1 -1
- package/core/ApolloClient.js +7 -3
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.js +2 -0
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts +4 -1
- package/core/QueryManager.js +26 -2
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +57 -20
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +57 -20
- package/core/masking.d.ts +6 -0
- package/core/masking.js +33 -15
- package/core/masking.js.map +1 -1
- package/dev/dev.cjs +66 -62
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +66 -62
- package/invariantErrorCodes.js +66 -61
- package/link/core/ApolloLink.js +2 -2
- package/link/core/core.cjs +2 -2
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +2 -2
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/http.cjs +3 -3
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +3 -3
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +2 -2
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
- package/link/utils/toPromise.js +1 -1
- package/link/utils/utils.cjs +2 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +2 -2
- package/link/utils/validateOperation.js +1 -1
- package/masking/types.d.ts +2 -2
- package/masking/types.js.map +1 -1
- package/package.json +4 -3
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs +3 -3
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +3 -3
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs +2 -2
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +2 -2
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs +9 -9
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +9 -9
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useLoadableQuery.js +2 -2
- package/react/hooks/useSubscription.js +3 -3
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/internal/cache/QueryReference.js +2 -2
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/internal.cjs +3 -3
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +3 -3
- package/react/parser/index.js +5 -5
- package/react/parser/parser.cjs +5 -5
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +5 -5
- package/testing/core/core.cjs +2 -2
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +2 -2
- package/testing/core/mocking/mockLink.js +2 -2
- package/testing/internal/ObservableStream.d.ts +11 -15
- package/testing/internal/ObservableStream.js +18 -62
- package/testing/internal/ObservableStream.js.map +1 -1
- package/testing/internal/index.d.ts +1 -2
- package/testing/internal/index.js +1 -2
- package/testing/internal/index.js.map +1 -1
- package/testing/internal/renderHelpers.d.ts +13 -2
- package/testing/internal/renderHelpers.js +20 -12
- package/testing/internal/renderHelpers.js.map +1 -1
- package/testing/matchers/index.js +0 -3
- package/testing/matchers/index.js.map +1 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/graphql/directives.js +7 -7
- package/utilities/graphql/fragments.d.ts +1 -0
- package/utilities/graphql/fragments.js +18 -3
- package/utilities/graphql/fragments.js.map +1 -1
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/graphql/transform.js +8 -2
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +1 -1
- package/utilities/index.js +1 -1
- package/utilities/index.js.map +1 -1
- package/utilities/utilities.cjs +41 -22
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +41 -22
- package/version.js +1 -1
- package/testing/internal/profile/Render.d.ts +0 -69
- package/testing/internal/profile/Render.js +0 -144
- package/testing/internal/profile/Render.js.map +0 -1
- package/testing/internal/profile/context.d.ts +0 -10
- package/testing/internal/profile/context.js +0 -14
- package/testing/internal/profile/context.js.map +0 -1
- package/testing/internal/profile/index.d.ts +0 -4
- package/testing/internal/profile/index.js +0 -2
- package/testing/internal/profile/index.js.map +0 -1
- package/testing/internal/profile/profile.d.ts +0 -109
- package/testing/internal/profile/profile.js +0 -304
- package/testing/internal/profile/profile.js.map +0 -1
- package/testing/internal/profile/traces.d.ts +0 -7
- package/testing/internal/profile/traces.js +0 -30
- package/testing/internal/profile/traces.js.map +0 -1
- package/testing/matchers/ProfiledComponent.d.ts +0 -8
- package/testing/matchers/ProfiledComponent.js +0 -110
- package/testing/matchers/ProfiledComponent.js.map +0 -1
package/core/core.cjs
CHANGED
|
@@ -12,6 +12,7 @@ var cache = require('../cache');
|
|
|
12
12
|
var errors = require('../errors');
|
|
13
13
|
var trie = require('@wry/trie');
|
|
14
14
|
var graphql = require('graphql');
|
|
15
|
+
var optimism = require('optimism');
|
|
15
16
|
var utils = require('../link/utils');
|
|
16
17
|
var tsInvariant = require('ts-invariant');
|
|
17
18
|
var graphqlTag = require('graphql-tag');
|
|
@@ -20,7 +21,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
20
21
|
|
|
21
22
|
var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
22
23
|
|
|
23
|
-
var version = "3.12.0-
|
|
24
|
+
var version = "3.12.0-rc.0";
|
|
24
25
|
|
|
25
26
|
function isNonNullObject(obj) {
|
|
26
27
|
return obj !== null && typeof obj === "object";
|
|
@@ -758,6 +759,8 @@ var ObservableQuery = (function (_super) {
|
|
|
758
759
|
return result && "data" in result ? tslib.__assign(tslib.__assign({}, result), { data: this.queryManager.maskOperation({
|
|
759
760
|
document: this.query,
|
|
760
761
|
data: result.data,
|
|
762
|
+
fetchPolicy: this.options.fetchPolicy,
|
|
763
|
+
id: this.queryId,
|
|
761
764
|
}) }) : result;
|
|
762
765
|
};
|
|
763
766
|
return ObservableQuery;
|
|
@@ -1071,6 +1074,7 @@ function shouldWriteResult(result, errorPolicy) {
|
|
|
1071
1074
|
return writeWithErrors;
|
|
1072
1075
|
}
|
|
1073
1076
|
|
|
1077
|
+
var disableWarningsSlot = new optimism.Slot();
|
|
1074
1078
|
function maskOperation(data, document, cache) {
|
|
1075
1079
|
var _a;
|
|
1076
1080
|
if (!cache.fragmentMatches) {
|
|
@@ -1080,7 +1084,7 @@ function maskOperation(data, document, cache) {
|
|
|
1080
1084
|
return data;
|
|
1081
1085
|
}
|
|
1082
1086
|
var definition = utilities.getOperationDefinition(document);
|
|
1083
|
-
globals.invariant(definition,
|
|
1087
|
+
globals.invariant(definition, 38);
|
|
1084
1088
|
if (data == null) {
|
|
1085
1089
|
return data;
|
|
1086
1090
|
}
|
|
@@ -1092,9 +1096,7 @@ function maskOperation(data, document, cache) {
|
|
|
1092
1096
|
};
|
|
1093
1097
|
var _b = maskSelectionSet(data, definition.selectionSet, context), masked = _b[0], changed = _b[1];
|
|
1094
1098
|
if (Object.isFrozen(data)) {
|
|
1095
|
-
|
|
1096
|
-
utilities.maybeDeepFreeze(masked);
|
|
1097
|
-
context.disableWarnings = false;
|
|
1099
|
+
disableWarningsSlot.withValue(true, utilities.maybeDeepFreeze, [masked]);
|
|
1098
1100
|
}
|
|
1099
1101
|
return changed ? masked : data;
|
|
1100
1102
|
}
|
|
@@ -1109,14 +1111,17 @@ function maskFragment(data, document, cache, fragmentName) {
|
|
|
1109
1111
|
return node.kind === graphql.Kind.FRAGMENT_DEFINITION;
|
|
1110
1112
|
});
|
|
1111
1113
|
if (typeof fragmentName === "undefined") {
|
|
1112
|
-
globals.invariant(fragments.length === 1,
|
|
1114
|
+
globals.invariant(fragments.length === 1, 39, fragments.length);
|
|
1113
1115
|
fragmentName = fragments[0].name.value;
|
|
1114
1116
|
}
|
|
1115
1117
|
var fragment = fragments.find(function (fragment) { return fragment.name.value === fragmentName; });
|
|
1116
|
-
globals.invariant(!!fragment,
|
|
1118
|
+
globals.invariant(!!fragment, 40, fragmentName);
|
|
1117
1119
|
if (data == null) {
|
|
1118
1120
|
return data;
|
|
1119
1121
|
}
|
|
1122
|
+
if (equal.equal(data, {})) {
|
|
1123
|
+
return data;
|
|
1124
|
+
}
|
|
1120
1125
|
var context = {
|
|
1121
1126
|
operationType: "fragment",
|
|
1122
1127
|
operationName: fragment.name.value,
|
|
@@ -1125,9 +1130,7 @@ function maskFragment(data, document, cache, fragmentName) {
|
|
|
1125
1130
|
};
|
|
1126
1131
|
var _a = maskSelectionSet(data, fragment.selectionSet, context), masked = _a[0], changed = _a[1];
|
|
1127
1132
|
if (Object.isFrozen(data)) {
|
|
1128
|
-
|
|
1129
|
-
utilities.maybeDeepFreeze(masked);
|
|
1130
|
-
context.disableWarnings = false;
|
|
1133
|
+
disableWarningsSlot.withValue(true, utilities.maybeDeepFreeze, [masked]);
|
|
1131
1134
|
}
|
|
1132
1135
|
return changed ? masked : data;
|
|
1133
1136
|
}
|
|
@@ -1151,7 +1154,10 @@ function maskSelectionSet(data, selectionSet, context, path) {
|
|
|
1151
1154
|
var keyName = utilities.resultKeyNameFromField(selection);
|
|
1152
1155
|
var childSelectionSet = selection.selectionSet;
|
|
1153
1156
|
memo[keyName] = data[keyName];
|
|
1154
|
-
if (
|
|
1157
|
+
if (memo[keyName] === void 0) {
|
|
1158
|
+
delete memo[keyName];
|
|
1159
|
+
}
|
|
1160
|
+
if (keyName in memo && childSelectionSet && data[keyName] !== null) {
|
|
1155
1161
|
var _b = maskSelectionSet(data[keyName], childSelectionSet, context, globalThis.__DEV__ !== false ? "".concat(path || "", ".").concat(keyName) : void 0), masked = _b[0], childChanged = _b[1];
|
|
1156
1162
|
if (childChanged ||
|
|
1157
1163
|
Object.keys(masked).length !== Object.keys(data[keyName]).length) {
|
|
@@ -1177,7 +1183,7 @@ function maskSelectionSet(data, selectionSet, context, path) {
|
|
|
1177
1183
|
var fragment = context.fragmentMap[fragmentName] ||
|
|
1178
1184
|
(context.fragmentMap[fragmentName] =
|
|
1179
1185
|
context.cache.lookupFragment(fragmentName));
|
|
1180
|
-
globals.invariant(fragment,
|
|
1186
|
+
globals.invariant(fragment, 41, fragmentName);
|
|
1181
1187
|
var mode = utilities.getFragmentMaskMode(selection);
|
|
1182
1188
|
if (mode === "mask") {
|
|
1183
1189
|
return [memo, true];
|
|
@@ -1195,7 +1201,7 @@ function maskSelectionSet(data, selectionSet, context, path) {
|
|
|
1195
1201
|
}
|
|
1196
1202
|
}
|
|
1197
1203
|
}, [Object.create(null), false]);
|
|
1198
|
-
if ("__typename" in data && !("__typename" in result[0])) {
|
|
1204
|
+
if (data && "__typename" in data && !("__typename" in result[0])) {
|
|
1199
1205
|
result[0].__typename = data.__typename;
|
|
1200
1206
|
}
|
|
1201
1207
|
return result;
|
|
@@ -1245,11 +1251,14 @@ function addFieldAccessorWarnings(memo, data, selectionSetNode, path, context) {
|
|
|
1245
1251
|
}, memo);
|
|
1246
1252
|
}
|
|
1247
1253
|
function addAccessorWarning(data, value, fieldName, path, context) {
|
|
1254
|
+
if (value === void 0) {
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1248
1257
|
var getValue = function () {
|
|
1249
|
-
if (
|
|
1258
|
+
if (disableWarningsSlot.getValue()) {
|
|
1250
1259
|
return value;
|
|
1251
1260
|
}
|
|
1252
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
1261
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(42, context.operationName ?
|
|
1253
1262
|
"".concat(context.operationType, " '").concat(context.operationName, "'")
|
|
1254
1263
|
: "anonymous ".concat(context.operationType), "".concat(path, ".").concat(fieldName).replace(/^\./, ""));
|
|
1255
1264
|
getValue = function () { return value; };
|
|
@@ -1270,7 +1279,7 @@ var issuedWarning = false;
|
|
|
1270
1279
|
function warnOnImproperCacheImplementation() {
|
|
1271
1280
|
if (!issuedWarning) {
|
|
1272
1281
|
issuedWarning = true;
|
|
1273
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
1282
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(43);
|
|
1274
1283
|
}
|
|
1275
1284
|
}
|
|
1276
1285
|
|
|
@@ -1288,6 +1297,7 @@ var QueryManager = (function () {
|
|
|
1288
1297
|
this.requestIdCounter = 1;
|
|
1289
1298
|
this.mutationIdCounter = 1;
|
|
1290
1299
|
this.inFlightLinkObservables = new trie.Trie(false);
|
|
1300
|
+
this.noCacheWarningsByQueryId = new Set();
|
|
1291
1301
|
var defaultDocumentTransform = new utilities.DocumentTransform(function (document) { return _this.cache.transformDocument(document); },
|
|
1292
1302
|
{ cache: false });
|
|
1293
1303
|
this.cache = options.cache;
|
|
@@ -1404,6 +1414,8 @@ var QueryManager = (function () {
|
|
|
1404
1414
|
resolve(tslib.__assign(tslib.__assign({}, storeResult), { data: self.maskOperation({
|
|
1405
1415
|
document: mutation,
|
|
1406
1416
|
data: storeResult.data,
|
|
1417
|
+
fetchPolicy: fetchPolicy,
|
|
1418
|
+
id: mutationId,
|
|
1407
1419
|
}) }));
|
|
1408
1420
|
}
|
|
1409
1421
|
},
|
|
@@ -1665,7 +1677,12 @@ var QueryManager = (function () {
|
|
|
1665
1677
|
var query = this.transform(options.query);
|
|
1666
1678
|
return this.fetchQuery(queryId, tslib.__assign(tslib.__assign({}, options), { query: query }))
|
|
1667
1679
|
.then(function (result) {
|
|
1668
|
-
return result && tslib.__assign(tslib.__assign({}, result), { data: _this.maskOperation({
|
|
1680
|
+
return result && tslib.__assign(tslib.__assign({}, result), { data: _this.maskOperation({
|
|
1681
|
+
document: query,
|
|
1682
|
+
data: result.data,
|
|
1683
|
+
fetchPolicy: options.fetchPolicy,
|
|
1684
|
+
id: queryId,
|
|
1685
|
+
}) });
|
|
1669
1686
|
})
|
|
1670
1687
|
.finally(function () { return _this.stopQuery(queryId); });
|
|
1671
1688
|
};
|
|
@@ -2078,7 +2095,23 @@ var QueryManager = (function () {
|
|
|
2078
2095
|
return results;
|
|
2079
2096
|
};
|
|
2080
2097
|
QueryManager.prototype.maskOperation = function (options) {
|
|
2098
|
+
var _a, _b, _c;
|
|
2081
2099
|
var document = options.document, data = options.data;
|
|
2100
|
+
if (globalThis.__DEV__ !== false) {
|
|
2101
|
+
var fetchPolicy = options.fetchPolicy, id = options.id;
|
|
2102
|
+
var operationType = (_a = utilities.getOperationDefinition(document)) === null || _a === void 0 ? void 0 : _a.operation;
|
|
2103
|
+
var operationId = ((_b = operationType === null || operationType === void 0 ? void 0 : operationType[0]) !== null && _b !== void 0 ? _b : "o") + id;
|
|
2104
|
+
if (this.dataMasking &&
|
|
2105
|
+
fetchPolicy === "no-cache" &&
|
|
2106
|
+
!utilities.isFullyUnmaskedOperation(document) &&
|
|
2107
|
+
!this.noCacheWarningsByQueryId.has(operationId)) {
|
|
2108
|
+
this.noCacheWarningsByQueryId.add(operationId);
|
|
2109
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
2110
|
+
37,
|
|
2111
|
+
(_c = utilities.getOperationName(document)) !== null && _c !== void 0 ? _c : "Unnamed ".concat(operationType !== null && operationType !== void 0 ? operationType : "operation")
|
|
2112
|
+
);
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2082
2115
|
return (this.dataMasking ?
|
|
2083
2116
|
maskOperation(data, document, this.cache)
|
|
2084
2117
|
: data);
|
|
@@ -2602,13 +2635,14 @@ var hasSuggestedDevtools = false;
|
|
|
2602
2635
|
var ApolloClient = (function () {
|
|
2603
2636
|
function ApolloClient(options) {
|
|
2604
2637
|
var _this = this;
|
|
2638
|
+
var _a;
|
|
2605
2639
|
this.resetStoreCallbacks = [];
|
|
2606
2640
|
this.clearStoreCallbacks = [];
|
|
2607
2641
|
if (!options.cache) {
|
|
2608
2642
|
throw globals.newInvariantError(16);
|
|
2609
2643
|
}
|
|
2610
|
-
var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, documentTransform = options.documentTransform,
|
|
2611
|
-
connectToDevTools = options.connectToDevTools,
|
|
2644
|
+
var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, documentTransform = options.documentTransform, _b = options.ssrMode, ssrMode = _b === void 0 ? false : _b, _c = options.ssrForceFetchDelay, ssrForceFetchDelay = _c === void 0 ? 0 : _c,
|
|
2645
|
+
connectToDevTools = options.connectToDevTools, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, defaultContext = options.defaultContext, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version, devtools = options.devtools, dataMasking = options.dataMasking;
|
|
2612
2646
|
var link = options.link;
|
|
2613
2647
|
if (!link) {
|
|
2614
2648
|
link =
|
|
@@ -2620,7 +2654,7 @@ var ApolloClient = (function () {
|
|
|
2620
2654
|
this.queryDeduplication = queryDeduplication;
|
|
2621
2655
|
this.defaultOptions = defaultOptions || Object.create(null);
|
|
2622
2656
|
this.typeDefs = typeDefs;
|
|
2623
|
-
this.devtoolsConfig = tslib.__assign(tslib.__assign({}, devtools), { enabled: (devtools === null || devtools === void 0 ? void 0 : devtools.enabled)
|
|
2657
|
+
this.devtoolsConfig = tslib.__assign(tslib.__assign({}, devtools), { enabled: (_a = devtools === null || devtools === void 0 ? void 0 : devtools.enabled) !== null && _a !== void 0 ? _a : connectToDevTools });
|
|
2624
2658
|
if (this.devtoolsConfig.enabled === undefined) {
|
|
2625
2659
|
this.devtoolsConfig.enabled = globalThis.__DEV__ !== false;
|
|
2626
2660
|
}
|
|
@@ -2751,11 +2785,14 @@ var ApolloClient = (function () {
|
|
|
2751
2785
|
};
|
|
2752
2786
|
ApolloClient.prototype.subscribe = function (options) {
|
|
2753
2787
|
var _this = this;
|
|
2788
|
+
var id = this.queryManager.generateQueryId();
|
|
2754
2789
|
return this.queryManager
|
|
2755
2790
|
.startGraphQLSubscription(options)
|
|
2756
2791
|
.map(function (result) { return (tslib.__assign(tslib.__assign({}, result), { data: _this.queryManager.maskOperation({
|
|
2757
2792
|
document: options.query,
|
|
2758
2793
|
data: result.data,
|
|
2794
|
+
fetchPolicy: options.fetchPolicy,
|
|
2795
|
+
id: id,
|
|
2759
2796
|
}) })); });
|
|
2760
2797
|
};
|
|
2761
2798
|
ApolloClient.prototype.readQuery = function (options, optimistic) {
|