@apollo/client 3.12.0-rc.2 → 3.12.0-rc.4

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.
Files changed (86) hide show
  1. package/.changeset/clean-turkeys-kick.md +5 -0
  2. package/.changeset/happy-months-happen.md +5 -0
  3. package/.changeset/perfect-jobs-flow.md +5 -0
  4. package/.changeset/pre.json +3 -0
  5. package/CHANGELOG.md +14 -0
  6. package/apollo-client.cjs +74 -72
  7. package/apollo-client.cjs.map +1 -1
  8. package/apollo-client.min.cjs +1 -1
  9. package/cache/cache.cjs +4 -166
  10. package/cache/cache.cjs.map +1 -1
  11. package/cache/cache.cjs.native.js +4 -166
  12. package/cache/core/cache.js +1 -1
  13. package/cache/core/cache.js.map +1 -1
  14. package/cache/inmemory/policies.js +1 -1
  15. package/cache/inmemory/policies.js.map +1 -1
  16. package/core/QueryManager.js +1 -1
  17. package/core/QueryManager.js.map +1 -1
  18. package/core/core.cjs +4 -189
  19. package/core/core.cjs.map +1 -1
  20. package/core/core.cjs.native.js +4 -189
  21. package/dev/dev.cjs +37 -37
  22. package/dev/dev.cjs.map +1 -1
  23. package/dev/dev.cjs.native.js +37 -37
  24. package/invariantErrorCodes.js +42 -42
  25. package/link/core/ApolloLink.js +2 -2
  26. package/link/core/core.cjs +2 -2
  27. package/link/core/core.cjs.map +1 -1
  28. package/link/core/core.cjs.native.js +2 -2
  29. package/link/http/checkFetcher.js +1 -1
  30. package/link/http/createHttpLink.js +1 -1
  31. package/link/http/http.cjs +3 -3
  32. package/link/http/http.cjs.map +1 -1
  33. package/link/http/http.cjs.native.js +3 -3
  34. package/link/http/serializeFetchParameter.js +1 -1
  35. package/link/persisted-queries/index.js +2 -2
  36. package/link/persisted-queries/persisted-queries.cjs +2 -2
  37. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  38. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  39. package/link/utils/toPromise.js +1 -1
  40. package/link/utils/utils.cjs +2 -2
  41. package/link/utils/utils.cjs.map +1 -1
  42. package/link/utils/utils.cjs.native.js +2 -2
  43. package/link/utils/validateOperation.js +1 -1
  44. package/masking/__benches__/types.bench.d.ts +2 -0
  45. package/masking/__benches__/types.bench.js +131 -0
  46. package/masking/__benches__/types.bench.js.map +1 -0
  47. package/masking/index.d.ts +3 -0
  48. package/masking/index.js +3 -1
  49. package/masking/index.js.map +1 -1
  50. package/masking/internal/types.d.ts +115 -9
  51. package/masking/internal/types.js.map +1 -1
  52. package/masking/maskDefinition.d.ts +14 -0
  53. package/{core/masking.js → masking/maskDefinition.js} +11 -83
  54. package/masking/maskDefinition.js.map +1 -0
  55. package/masking/maskFragment.d.ts +4 -0
  56. package/masking/maskFragment.js +43 -0
  57. package/masking/maskFragment.js.map +1 -0
  58. package/masking/maskOperation.d.ts +4 -0
  59. package/masking/maskOperation.js +29 -0
  60. package/masking/maskOperation.js.map +1 -0
  61. package/masking/masking.cjs +202 -0
  62. package/masking/masking.cjs.map +1 -1
  63. package/masking/masking.cjs.native.js +202 -0
  64. package/masking/types.d.ts +4 -4
  65. package/masking/types.js.map +1 -1
  66. package/masking/utils.d.ts +11 -0
  67. package/masking/utils.js +17 -0
  68. package/masking/utils.js.map +1 -0
  69. package/package.json +3 -1
  70. package/react/hoc/hoc.cjs.map +1 -1
  71. package/react/hoc/mutation-hoc.js +3 -2
  72. package/react/hoc/mutation-hoc.js.map +1 -1
  73. package/react/internal/internal.cjs +1 -1
  74. package/react/internal/internal.cjs.map +1 -1
  75. package/react/internal/internal.cjs.native.js +1 -1
  76. package/react/types/types.d.ts +5 -1
  77. package/react/types/types.documentation.d.ts +7 -1
  78. package/react/types/types.documentation.js.map +1 -1
  79. package/testing/internal/scenarios/index.d.ts +1 -0
  80. package/testing/internal/scenarios/index.js.map +1 -1
  81. package/utilities/globals/globals.cjs +1 -1
  82. package/utilities/globals/globals.cjs.map +1 -1
  83. package/utilities/globals/globals.cjs.native.js +1 -1
  84. package/version.js +1 -1
  85. package/core/masking.d.ts +0 -10
  86. package/core/masking.js.map +0 -1
package/core/core.cjs CHANGED
@@ -11,8 +11,8 @@ var utilities = require('../utilities');
11
11
  var cache = require('../cache');
12
12
  var errors = require('../errors');
13
13
  var trie = require('@wry/trie');
14
+ var masking = require('../masking');
14
15
  var graphql = require('graphql');
15
- var optimism = require('optimism');
16
16
  var utils = require('../link/utils');
17
17
  var tsInvariant = require('ts-invariant');
18
18
  var graphqlTag = require('graphql-tag');
@@ -21,7 +21,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
21
21
 
22
22
  var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
23
23
 
24
- var version = "3.12.0-rc.2";
24
+ var version = "3.12.0-rc.4";
25
25
 
26
26
  function isNonNullObject(obj) {
27
27
  return obj !== null && typeof obj === "object";
@@ -1074,191 +1074,6 @@ function shouldWriteResult(result, errorPolicy) {
1074
1074
  return writeWithErrors;
1075
1075
  }
1076
1076
 
1077
- var MapImpl = utilities.canUseWeakMap ? WeakMap : Map;
1078
- var SetImpl = utilities.canUseWeakSet ? WeakSet : Set;
1079
- var disableWarningsSlot = new optimism.Slot();
1080
- function maskOperation(data, document, cache) {
1081
- var _a;
1082
- if (!cache.fragmentMatches) {
1083
- if (globalThis.__DEV__ !== false) {
1084
- warnOnImproperCacheImplementation();
1085
- }
1086
- return data;
1087
- }
1088
- var definition = utilities.getOperationDefinition(document);
1089
- globals.invariant(definition, 38);
1090
- if (data == null) {
1091
- return data;
1092
- }
1093
- return maskDefinition(data, definition.selectionSet, {
1094
- operationType: definition.operation,
1095
- operationName: (_a = definition.name) === null || _a === void 0 ? void 0 : _a.value,
1096
- fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(document)),
1097
- cache: cache,
1098
- mutableTargets: new MapImpl(),
1099
- knownChanged: new SetImpl(),
1100
- });
1101
- }
1102
- function maskFragment(data, document, cache, fragmentName) {
1103
- if (!cache.fragmentMatches) {
1104
- if (globalThis.__DEV__ !== false) {
1105
- warnOnImproperCacheImplementation();
1106
- }
1107
- return data;
1108
- }
1109
- var fragments = document.definitions.filter(function (node) {
1110
- return node.kind === graphql.Kind.FRAGMENT_DEFINITION;
1111
- });
1112
- if (typeof fragmentName === "undefined") {
1113
- globals.invariant(fragments.length === 1, 39, fragments.length);
1114
- fragmentName = fragments[0].name.value;
1115
- }
1116
- var fragment = fragments.find(function (fragment) { return fragment.name.value === fragmentName; });
1117
- globals.invariant(!!fragment, 40, fragmentName);
1118
- if (data == null) {
1119
- return data;
1120
- }
1121
- if (equal.equal(data, {})) {
1122
- return data;
1123
- }
1124
- return maskDefinition(data, fragment.selectionSet, {
1125
- operationType: "fragment",
1126
- operationName: fragment.name.value,
1127
- fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(document)),
1128
- cache: cache,
1129
- mutableTargets: new MapImpl(),
1130
- knownChanged: new SetImpl(),
1131
- });
1132
- }
1133
- function maskDefinition(data, selectionSet, context) {
1134
- return disableWarningsSlot.withValue(true, function () {
1135
- var masked = maskSelectionSet(data, selectionSet, context, false);
1136
- if (Object.isFrozen(data)) {
1137
- utilities.maybeDeepFreeze(masked);
1138
- }
1139
- return masked;
1140
- });
1141
- }
1142
- function getMutableTarget(data, mutableTargets) {
1143
- if (mutableTargets.has(data)) {
1144
- return mutableTargets.get(data);
1145
- }
1146
- var mutableTarget = Array.isArray(data) ? [] : Object.create(null);
1147
- mutableTargets.set(data, mutableTarget);
1148
- return mutableTarget;
1149
- }
1150
- function maskSelectionSet(data, selectionSet, context, migration, path) {
1151
- var _a;
1152
- var knownChanged = context.knownChanged;
1153
- if (Array.isArray(data)) {
1154
- var target = getMutableTarget(data, context.mutableTargets);
1155
- for (var _i = 0, _b = Array.from(data.entries()); _i < _b.length; _i++) {
1156
- var _c = _b[_i], index = _c[0], item = _c[1];
1157
- if (item === null) {
1158
- target[index] = null;
1159
- continue;
1160
- }
1161
- var masked = maskSelectionSet(item, selectionSet, context, migration, globalThis.__DEV__ !== false ? "".concat(path || "", "[").concat(index, "]") : void 0);
1162
- if (knownChanged.has(masked)) {
1163
- knownChanged.add(target);
1164
- }
1165
- target[index] = masked;
1166
- }
1167
- return knownChanged.has(target) ? target : data;
1168
- }
1169
- var memo = getMutableTarget(data, context.mutableTargets);
1170
- for (var _d = 0, _e = selectionSet.selections; _d < _e.length; _d++) {
1171
- var selection = _e[_d];
1172
- var value = void 0;
1173
- if (migration) {
1174
- knownChanged.add(memo);
1175
- }
1176
- if (selection.kind === graphql.Kind.FIELD) {
1177
- var keyName = utilities.resultKeyNameFromField(selection);
1178
- var childSelectionSet = selection.selectionSet;
1179
- value = memo[keyName] || data[keyName];
1180
- if (value === void 0) {
1181
- continue;
1182
- }
1183
- if (childSelectionSet && value !== null) {
1184
- var masked = maskSelectionSet(data[keyName], childSelectionSet, context, migration, globalThis.__DEV__ !== false ? "".concat(path || "", ".").concat(keyName) : void 0);
1185
- if (knownChanged.has(masked)) {
1186
- value = masked;
1187
- }
1188
- }
1189
- if (!(globalThis.__DEV__ !== false)) {
1190
- memo[keyName] = value;
1191
- }
1192
- if (globalThis.__DEV__ !== false) {
1193
- if (migration &&
1194
- keyName !== "__typename" &&
1195
- !((_a = Object.getOwnPropertyDescriptor(memo, keyName)) === null || _a === void 0 ? void 0 : _a.value)) {
1196
- Object.defineProperty(memo, keyName, getAccessorWarningDescriptor(keyName, value, path || "", context.operationName, context.operationType));
1197
- }
1198
- else {
1199
- delete memo[keyName];
1200
- memo[keyName] = value;
1201
- }
1202
- }
1203
- }
1204
- if (selection.kind === graphql.Kind.INLINE_FRAGMENT &&
1205
- (!selection.typeCondition ||
1206
- context.cache.fragmentMatches(selection, data.__typename))) {
1207
- value = maskSelectionSet(data, selection.selectionSet, context, migration, path);
1208
- }
1209
- if (selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
1210
- var fragmentName = selection.name.value;
1211
- var fragment = context.fragmentMap[fragmentName] ||
1212
- (context.fragmentMap[fragmentName] =
1213
- context.cache.lookupFragment(fragmentName));
1214
- globals.invariant(fragment, 41, fragmentName);
1215
- var mode = utilities.getFragmentMaskMode(selection);
1216
- if (mode !== "mask") {
1217
- value = maskSelectionSet(data, fragment.selectionSet, context, mode === "migrate", path);
1218
- }
1219
- }
1220
- if (knownChanged.has(value)) {
1221
- knownChanged.add(memo);
1222
- }
1223
- }
1224
- if ("__typename" in data && !("__typename" in memo)) {
1225
- memo.__typename = data.__typename;
1226
- }
1227
- if (Object.keys(memo).length !== Object.keys(data).length) {
1228
- knownChanged.add(memo);
1229
- }
1230
- return knownChanged.has(memo) ? memo : data;
1231
- }
1232
- function getAccessorWarningDescriptor(fieldName, value, path, operationName, operationType) {
1233
- var getValue = function () {
1234
- if (disableWarningsSlot.getValue()) {
1235
- return value;
1236
- }
1237
- globalThis.__DEV__ !== false && globals.invariant.warn(42, operationName ?
1238
- "".concat(operationType, " '").concat(operationName, "'")
1239
- : "anonymous ".concat(operationType), "".concat(path, ".").concat(fieldName).replace(/^\./, ""));
1240
- getValue = function () { return value; };
1241
- return value;
1242
- };
1243
- return {
1244
- get: function () {
1245
- return getValue();
1246
- },
1247
- set: function (newValue) {
1248
- getValue = function () { return newValue; };
1249
- },
1250
- enumerable: true,
1251
- configurable: true,
1252
- };
1253
- }
1254
- var issuedWarning = false;
1255
- function warnOnImproperCacheImplementation() {
1256
- if (!issuedWarning) {
1257
- issuedWarning = true;
1258
- globalThis.__DEV__ !== false && globals.invariant.warn(43);
1259
- }
1260
- }
1261
-
1262
1077
  var hasOwnProperty = Object.prototype.hasOwnProperty;
1263
1078
  var IGNORE = Object.create(null);
1264
1079
  var QueryManager = (function () {
@@ -2089,13 +1904,13 @@ var QueryManager = (function () {
2089
1904
  }
2090
1905
  }
2091
1906
  return (this.dataMasking ?
2092
- maskOperation(data, document, this.cache)
1907
+ masking.maskOperation(data, document, this.cache)
2093
1908
  : data);
2094
1909
  };
2095
1910
  QueryManager.prototype.maskFragment = function (options) {
2096
1911
  var data = options.data, fragment = options.fragment, fragmentName = options.fragmentName;
2097
1912
  return this.dataMasking ?
2098
- maskFragment(data, fragment, this.cache, fragmentName)
1913
+ masking.maskFragment(data, fragment, this.cache, fragmentName)
2099
1914
  : data;
2100
1915
  };
2101
1916
  QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, _a,