@apollo/client 3.12.0-alpha.0 → 3.12.0-rc.1

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 (148) hide show
  1. package/.changeset/brown-readers-smash.md +5 -0
  2. package/.changeset/cold-apes-bow.md +5 -0
  3. package/.changeset/early-bobcats-eat.md +5 -0
  4. package/.changeset/flat-beans-knock.md +15 -0
  5. package/.changeset/gorgeous-zebras-confess.md +5 -0
  6. package/.changeset/kind-toys-tie.md +5 -0
  7. package/.changeset/long-zoos-ring.md +5 -0
  8. package/.changeset/nervous-owls-hear.md +5 -0
  9. package/.changeset/nice-countries-share.md +5 -0
  10. package/.changeset/pre.json +13 -2
  11. package/.changeset/slimy-points-end.md +5 -0
  12. package/.changeset/small-bears-confess.md +5 -0
  13. package/CHANGELOG.md +52 -0
  14. package/apollo-client.cjs +187 -93
  15. package/apollo-client.cjs.map +1 -1
  16. package/apollo-client.min.cjs +1 -1
  17. package/cache/cache.cjs +59 -25
  18. package/cache/cache.cjs.map +1 -1
  19. package/cache/cache.cjs.native.js +59 -25
  20. package/cache/inmemory/policies.js +12 -9
  21. package/cache/inmemory/policies.js.map +1 -1
  22. package/config/jest/setup.js +5 -0
  23. package/config/jest/setup.js.map +1 -1
  24. package/core/ApolloClient.js +7 -3
  25. package/core/ApolloClient.js.map +1 -1
  26. package/core/ObservableQuery.js +2 -0
  27. package/core/ObservableQuery.js.map +1 -1
  28. package/core/QueryManager.d.ts +4 -1
  29. package/core/QueryManager.js +26 -2
  30. package/core/QueryManager.js.map +1 -1
  31. package/core/core.cjs +86 -25
  32. package/core/core.cjs.map +1 -1
  33. package/core/core.cjs.native.js +86 -25
  34. package/core/masking.d.ts +6 -0
  35. package/core/masking.js +62 -20
  36. package/core/masking.js.map +1 -1
  37. package/dev/dev.cjs +66 -62
  38. package/dev/dev.cjs.map +1 -1
  39. package/dev/dev.cjs.native.js +66 -62
  40. package/invariantErrorCodes.js +66 -61
  41. package/link/core/ApolloLink.js +2 -2
  42. package/link/core/core.cjs +2 -2
  43. package/link/core/core.cjs.map +1 -1
  44. package/link/core/core.cjs.native.js +2 -2
  45. package/link/http/checkFetcher.js +1 -1
  46. package/link/http/createHttpLink.js +1 -1
  47. package/link/http/http.cjs +3 -3
  48. package/link/http/http.cjs.map +1 -1
  49. package/link/http/http.cjs.native.js +3 -3
  50. package/link/http/serializeFetchParameter.js +1 -1
  51. package/link/persisted-queries/index.js +2 -2
  52. package/link/persisted-queries/index.js.map +1 -1
  53. package/link/persisted-queries/persisted-queries.cjs +2 -2
  54. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  55. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  56. package/link/utils/toPromise.js +1 -1
  57. package/link/utils/utils.cjs +2 -2
  58. package/link/utils/utils.cjs.map +1 -1
  59. package/link/utils/utils.cjs.native.js +2 -2
  60. package/link/utils/validateOperation.js +1 -1
  61. package/masking/internal/types.d.ts +2 -2
  62. package/masking/internal/types.js.map +1 -1
  63. package/masking/types.d.ts +2 -2
  64. package/masking/types.js.map +1 -1
  65. package/package.json +4 -3
  66. package/react/context/ApolloConsumer.js +1 -1
  67. package/react/context/ApolloContext.js +1 -1
  68. package/react/context/ApolloProvider.js +1 -1
  69. package/react/context/context.cjs +3 -3
  70. package/react/context/context.cjs.map +1 -1
  71. package/react/context/context.cjs.native.js +3 -3
  72. package/react/hoc/hoc-utils.js +1 -1
  73. package/react/hoc/hoc.cjs +2 -2
  74. package/react/hoc/hoc.cjs.map +1 -1
  75. package/react/hoc/hoc.cjs.native.js +2 -2
  76. package/react/hoc/withApollo.js +1 -1
  77. package/react/hooks/hooks.cjs +34 -20
  78. package/react/hooks/hooks.cjs.map +1 -1
  79. package/react/hooks/hooks.cjs.native.js +34 -20
  80. package/react/hooks/useApolloClient.js +1 -1
  81. package/react/hooks/useFragment.d.ts +1 -1
  82. package/react/hooks/useFragment.js +33 -19
  83. package/react/hooks/useFragment.js.map +1 -1
  84. package/react/hooks/useLoadableQuery.js +2 -2
  85. package/react/hooks/useSubscription.js +3 -3
  86. package/react/hooks/useSuspenseQuery.js +2 -2
  87. package/react/hooks/useSyncExternalStore.js +1 -1
  88. package/react/internal/cache/QueryReference.js +2 -2
  89. package/react/internal/cache/QueryReference.js.map +1 -1
  90. package/react/internal/internal.cjs +3 -3
  91. package/react/internal/internal.cjs.map +1 -1
  92. package/react/internal/internal.cjs.native.js +3 -3
  93. package/react/parser/index.js +5 -5
  94. package/react/parser/parser.cjs +5 -5
  95. package/react/parser/parser.cjs.map +1 -1
  96. package/react/parser/parser.cjs.native.js +5 -5
  97. package/testing/core/core.cjs +2 -2
  98. package/testing/core/core.cjs.map +1 -1
  99. package/testing/core/core.cjs.native.js +2 -2
  100. package/testing/core/mocking/mockLink.js +2 -2
  101. package/testing/internal/ObservableStream.d.ts +11 -15
  102. package/testing/internal/ObservableStream.js +18 -62
  103. package/testing/internal/ObservableStream.js.map +1 -1
  104. package/testing/internal/index.d.ts +1 -2
  105. package/testing/internal/index.js +1 -2
  106. package/testing/internal/index.js.map +1 -1
  107. package/testing/internal/renderHelpers.d.ts +13 -2
  108. package/testing/internal/renderHelpers.js +20 -12
  109. package/testing/internal/renderHelpers.js.map +1 -1
  110. package/testing/matchers/index.js +0 -3
  111. package/testing/matchers/index.js.map +1 -1
  112. package/utilities/globals/globals.cjs +1 -1
  113. package/utilities/globals/globals.cjs.map +1 -1
  114. package/utilities/globals/globals.cjs.native.js +1 -1
  115. package/utilities/graphql/DocumentTransform.js +1 -1
  116. package/utilities/graphql/directives.js +7 -7
  117. package/utilities/graphql/fragments.d.ts +1 -0
  118. package/utilities/graphql/fragments.js +18 -3
  119. package/utilities/graphql/fragments.js.map +1 -1
  120. package/utilities/graphql/getFromAST.js +8 -8
  121. package/utilities/graphql/storeUtils.js +1 -1
  122. package/utilities/graphql/transform.js +8 -2
  123. package/utilities/graphql/transform.js.map +1 -1
  124. package/utilities/index.d.ts +1 -1
  125. package/utilities/index.js +1 -1
  126. package/utilities/index.js.map +1 -1
  127. package/utilities/utilities.cjs +41 -22
  128. package/utilities/utilities.cjs.map +1 -1
  129. package/utilities/utilities.cjs.native.js +41 -22
  130. package/version.js +1 -1
  131. package/testing/internal/profile/Render.d.ts +0 -69
  132. package/testing/internal/profile/Render.js +0 -144
  133. package/testing/internal/profile/Render.js.map +0 -1
  134. package/testing/internal/profile/context.d.ts +0 -10
  135. package/testing/internal/profile/context.js +0 -14
  136. package/testing/internal/profile/context.js.map +0 -1
  137. package/testing/internal/profile/index.d.ts +0 -4
  138. package/testing/internal/profile/index.js +0 -2
  139. package/testing/internal/profile/index.js.map +0 -1
  140. package/testing/internal/profile/profile.d.ts +0 -109
  141. package/testing/internal/profile/profile.js +0 -304
  142. package/testing/internal/profile/profile.js.map +0 -1
  143. package/testing/internal/profile/traces.d.ts +0 -7
  144. package/testing/internal/profile/traces.js +0 -30
  145. package/testing/internal/profile/traces.js.map +0 -1
  146. package/testing/matchers/ProfiledComponent.d.ts +0 -8
  147. package/testing/matchers/ProfiledComponent.js +0 -110
  148. package/testing/matchers/ProfiledComponent.js.map +0 -1
@@ -126,6 +126,7 @@ function directiveIsNonreactive(dir) {
126
126
  return dir.name.value === "nonreactive";
127
127
  }
128
128
 
129
+ var disableWarningsSlot = new optimism.Slot();
129
130
  function maskFragment(data, document, cache, fragmentName) {
130
131
  if (!cache.fragmentMatches) {
131
132
  if (globalThis.__DEV__ !== false) {
@@ -137,14 +138,17 @@ function maskFragment(data, document, cache, fragmentName) {
137
138
  return node.kind === graphql.Kind.FRAGMENT_DEFINITION;
138
139
  });
139
140
  if (typeof fragmentName === "undefined") {
140
- globals.invariant(fragments.length === 1, 38, fragments.length);
141
+ globals.invariant(fragments.length === 1, 39, fragments.length);
141
142
  fragmentName = fragments[0].name.value;
142
143
  }
143
144
  var fragment = fragments.find(function (fragment) { return fragment.name.value === fragmentName; });
144
- globals.invariant(!!fragment, 39, fragmentName);
145
+ globals.invariant(!!fragment, 40, fragmentName);
145
146
  if (data == null) {
146
147
  return data;
147
148
  }
149
+ if (equal.equal(data, {})) {
150
+ return data;
151
+ }
148
152
  var context = {
149
153
  operationType: "fragment",
150
154
  operationName: fragment.name.value,
@@ -153,9 +157,7 @@ function maskFragment(data, document, cache, fragmentName) {
153
157
  };
154
158
  var _a = maskSelectionSet(data, fragment.selectionSet, context), masked = _a[0], changed = _a[1];
155
159
  if (Object.isFrozen(data)) {
156
- context.disableWarnings = true;
157
- utilities.maybeDeepFreeze(masked);
158
- context.disableWarnings = false;
160
+ disableWarningsSlot.withValue(true, utilities.maybeDeepFreeze, [masked]);
159
161
  }
160
162
  return changed ? masked : data;
161
163
  }
@@ -172,14 +174,22 @@ function maskSelectionSet(data, selectionSet, context, path) {
172
174
  });
173
175
  return [changed_1 ? masked : data, changed_1];
174
176
  }
175
- var result = selectionSet.selections.reduce(function (_a, selection) {
177
+ var result = selectionSet.selections
178
+ .concat()
179
+ .sort(sortFragmentsLast)
180
+ .reduce(function (_a, selection) {
176
181
  var memo = _a[0], changed = _a[1];
177
182
  switch (selection.kind) {
178
183
  case graphql.Kind.FIELD: {
179
184
  var keyName = utilities.resultKeyNameFromField(selection);
180
185
  var childSelectionSet = selection.selectionSet;
181
186
  memo[keyName] = data[keyName];
182
- if (childSelectionSet && data[keyName] !== null) {
187
+ if (memo[keyName] === void 0) {
188
+ delete memo[keyName];
189
+ }
190
+ if (keyName in memo &&
191
+ childSelectionSet &&
192
+ data[keyName] !== null) {
183
193
  var _b = maskSelectionSet(data[keyName], childSelectionSet, context, globalThis.__DEV__ !== false ? "".concat(path || "", ".").concat(keyName) : void 0), masked = _b[0], childChanged = _b[1];
184
194
  if (childChanged ||
185
195
  Object.keys(masked).length !== Object.keys(data[keyName]).length) {
@@ -205,7 +215,7 @@ function maskSelectionSet(data, selectionSet, context, path) {
205
215
  var fragment = context.fragmentMap[fragmentName] ||
206
216
  (context.fragmentMap[fragmentName] =
207
217
  context.cache.lookupFragment(fragmentName));
208
- globals.invariant(fragment, 40, fragmentName);
218
+ globals.invariant(fragment, 41, fragmentName);
209
219
  var mode = utilities.getFragmentMaskMode(selection);
210
220
  if (mode === "mask") {
211
221
  return [memo, true];
@@ -223,7 +233,7 @@ function maskSelectionSet(data, selectionSet, context, path) {
223
233
  }
224
234
  }
225
235
  }, [Object.create(null), false]);
226
- if ("__typename" in data && !("__typename" in result[0])) {
236
+ if (data && "__typename" in data && !("__typename" in result[0])) {
227
237
  result[0].__typename = data.__typename;
228
238
  }
229
239
  return result;
@@ -234,20 +244,29 @@ function addFieldAccessorWarnings(memo, data, selectionSetNode, path, context) {
234
244
  return addFieldAccessorWarnings(memo[index] || Object.create(null), item, selectionSetNode, "".concat(path, "[").concat(index, "]"), context);
235
245
  });
236
246
  }
237
- return selectionSetNode.selections.reduce(function (memo, selection) {
247
+ return selectionSetNode.selections
248
+ .concat()
249
+ .sort(sortFragmentsLast)
250
+ .reduce(function (memo, selection) {
238
251
  switch (selection.kind) {
239
252
  case graphql.Kind.FIELD: {
240
253
  var keyName = utilities.resultKeyNameFromField(selection);
241
254
  var childSelectionSet = selection.selectionSet;
242
- if (keyName in memo) {
255
+ if (keyName in memo && !childSelectionSet) {
243
256
  return memo;
244
257
  }
245
258
  var value = data[keyName];
246
259
  if (childSelectionSet) {
247
- value = addFieldAccessorWarnings(memo[keyName] || Object.create(null), data[keyName], childSelectionSet, "".concat(path, ".").concat(keyName), context);
260
+ value = addFieldAccessorWarnings(memo[keyName] ||
261
+ (Array.isArray(data[keyName]) ? [] : Object.create(null)), data[keyName], childSelectionSet, "".concat(path, ".").concat(keyName), context);
248
262
  }
249
263
  if (globalThis.__DEV__ !== false) {
250
- addAccessorWarning(memo, value, keyName, path, context);
264
+ if (keyName in memo) {
265
+ memo[keyName] = value;
266
+ }
267
+ else {
268
+ addAccessorWarning(memo, value, keyName, path, context);
269
+ }
251
270
  }
252
271
  if (!(globalThis.__DEV__ !== false)) {
253
272
  memo[keyName] = data[keyName];
@@ -255,6 +274,10 @@ function addFieldAccessorWarnings(memo, data, selectionSetNode, path, context) {
255
274
  return memo;
256
275
  }
257
276
  case graphql.Kind.INLINE_FRAGMENT: {
277
+ if (selection.typeCondition &&
278
+ !context.cache.fragmentMatches(selection, data.__typename)) {
279
+ return memo;
280
+ }
258
281
  return addFieldAccessorWarnings(memo, data, selection.selectionSet, path, context);
259
282
  }
260
283
  case graphql.Kind.FRAGMENT_SPREAD: {
@@ -273,11 +296,14 @@ function addFieldAccessorWarnings(memo, data, selectionSetNode, path, context) {
273
296
  }, memo);
274
297
  }
275
298
  function addAccessorWarning(data, value, fieldName, path, context) {
299
+ if (value === void 0) {
300
+ return;
301
+ }
276
302
  var getValue = function () {
277
- if (context.disableWarnings) {
303
+ if (disableWarningsSlot.getValue()) {
278
304
  return value;
279
305
  }
280
- globalThis.__DEV__ !== false && globals.invariant.warn(41, context.operationName ?
306
+ globalThis.__DEV__ !== false && globals.invariant.warn(42, context.operationName ?
281
307
  "".concat(context.operationType, " '").concat(context.operationName, "'")
282
308
  : "anonymous ".concat(context.operationType), "".concat(path, ".").concat(fieldName).replace(/^\./, ""));
283
309
  getValue = function () { return value; };
@@ -298,9 +324,15 @@ var issuedWarning = false;
298
324
  function warnOnImproperCacheImplementation() {
299
325
  if (!issuedWarning) {
300
326
  issuedWarning = true;
301
- globalThis.__DEV__ !== false && globals.invariant.warn(42);
327
+ globalThis.__DEV__ !== false && globals.invariant.warn(43);
302
328
  }
303
329
  }
330
+ function sortFragmentsLast(a, b) {
331
+ if (a.kind === b.kind) {
332
+ return 0;
333
+ }
334
+ return a.kind === graphql.Kind.FRAGMENT_SPREAD ? 1 : -1;
335
+ }
304
336
 
305
337
  var ApolloCache = (function () {
306
338
  function ApolloCache() {
@@ -1648,16 +1680,18 @@ var Policies = (function () {
1648
1680
  var id;
1649
1681
  var policy = typename && this.getTypePolicy(typename);
1650
1682
  var keyFn = (policy && policy.keyFn) || this.config.dataIdFromObject;
1651
- while (keyFn) {
1652
- var specifierOrId = keyFn(tslib.__assign(tslib.__assign({}, object), storeObject), context);
1653
- if (utilities.isArray(specifierOrId)) {
1654
- keyFn = keyFieldsFnFromSpecifier(specifierOrId);
1655
- }
1656
- else {
1657
- id = specifierOrId;
1658
- break;
1683
+ disableWarningsSlot.withValue(true, function () {
1684
+ while (keyFn) {
1685
+ var specifierOrId = keyFn(tslib.__assign(tslib.__assign({}, object), storeObject), context);
1686
+ if (utilities.isArray(specifierOrId)) {
1687
+ keyFn = keyFieldsFnFromSpecifier(specifierOrId);
1688
+ }
1689
+ else {
1690
+ id = specifierOrId;
1691
+ break;
1692
+ }
1659
1693
  }
1660
- }
1694
+ });
1661
1695
  id = id ? String(id) : void 0;
1662
1696
  return context.keyObject ? [id, context.keyObject] : [id];
1663
1697
  };
@@ -4,6 +4,7 @@ import { storeKeyNameFromField, argumentsObjectFromField, isReference, getStoreK
4
4
  import { hasOwn, fieldNameFromStoreName, storeValueIsStoreObject, selectionSetMatchesResult, TypeOrFieldNameRegExp, defaultDataIdFromObject, isArray, } from "./helpers.js";
5
5
  import { cacheSlot } from "./reactiveVars.js";
6
6
  import { keyArgsFnFromSpecifier, keyFieldsFnFromSpecifier, } from "./key-extractor.js";
7
+ import { disableWarningsSlot } from "../../core/masking.js";
7
8
  function argsFromFieldSpecifier(spec) {
8
9
  return (spec.args !== void 0 ? spec.args
9
10
  : spec.field ? argumentsObjectFromField(spec.field, spec.variables)
@@ -75,16 +76,18 @@ var Policies = /** @class */ (function () {
75
76
  var id;
76
77
  var policy = typename && this.getTypePolicy(typename);
77
78
  var keyFn = (policy && policy.keyFn) || this.config.dataIdFromObject;
78
- while (keyFn) {
79
- var specifierOrId = keyFn(__assign(__assign({}, object), storeObject), context);
80
- if (isArray(specifierOrId)) {
81
- keyFn = keyFieldsFnFromSpecifier(specifierOrId);
82
- }
83
- else {
84
- id = specifierOrId;
85
- break;
79
+ disableWarningsSlot.withValue(true, function () {
80
+ while (keyFn) {
81
+ var specifierOrId = keyFn(__assign(__assign({}, object), storeObject), context);
82
+ if (isArray(specifierOrId)) {
83
+ keyFn = keyFieldsFnFromSpecifier(specifierOrId);
84
+ }
85
+ else {
86
+ id = specifierOrId;
87
+ break;
88
+ }
86
89
  }
87
- }
90
+ });
88
91
  id = id ? String(id) : void 0;
89
92
  return context.keyObject ? [id, context.keyObject] : [id];
90
93
  };
@@ -1 +1 @@
1
- {"version":3,"file":"policies.js","sourceRoot":"","sources":["../../../src/cache/inmemory/policies.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAehF,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,WAAW,EACX,eAAe,EACf,eAAe,EACf,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EACL,MAAM,EACN,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,EACrB,uBAAuB,EACvB,OAAO,GACR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAY9C,OAAO,EACL,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAkH5B,SAAS,sBAAsB,CAAC,IAAoB;IAClD,OAAO,CACL,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI;QAChC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC;YACnE,CAAC,CAAC,IAAI,CACP,CAAC;AACJ,CAAC;AA6FD,IAAM,eAAe,GAAsB,cAAM,OAAA,KAAK,CAAC,EAAN,CAAM,CAAC;AACxD,IAAM,eAAe,GAAoB,UAAC,KAAK,EAAE,OAAO,IAAK,OAAA,OAAO,CAAC,SAAS,EAAjB,CAAiB,CAAC;AAE/E,oEAAoE;AACpE,iCAAiC;AACjC,IAAM,WAAW,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gE;gBAChE,gCAAgC;gBAChC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACtC,OAAO,QAAQ,CAAC;YAClB,CAAC;YAED,IACE,uBAAuB,CAAC,QAAQ,CAAC;gBACjC,uBAAuB,CAAC,QAAQ,CAAC,EACjC,CAAC;gBACD,6BAAY,QAAQ,GAAK,QAAQ,EAAG;YACtC,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { invariant, newInvariantError } from \"../../utilities/globals/index.js\";\n\nimport type {\n InlineFragmentNode,\n FragmentDefinitionNode,\n SelectionSetNode,\n FieldNode,\n} from \"graphql\";\n\nimport type {\n FragmentMap,\n StoreValue,\n StoreObject,\n Reference,\n} from \"../../utilities/index.js\";\nimport {\n storeKeyNameFromField,\n argumentsObjectFromField,\n isReference,\n getStoreKeyName,\n isNonNullObject,\n stringifyForDisplay,\n} from \"../../utilities/index.js\";\nimport type {\n IdGetter,\n MergeInfo,\n NormalizedCache,\n ReadMergeModifyContext,\n} from \"./types.js\";\nimport {\n hasOwn,\n fieldNameFromStoreName,\n storeValueIsStoreObject,\n selectionSetMatchesResult,\n TypeOrFieldNameRegExp,\n defaultDataIdFromObject,\n isArray,\n} from \"./helpers.js\";\nimport { cacheSlot } from \"./reactiveVars.js\";\nimport type { InMemoryCache } from \"./inMemoryCache.js\";\nimport type {\n SafeReadonly,\n FieldSpecifier,\n ToReferenceFunction,\n ReadFieldFunction,\n ReadFieldOptions,\n CanReadFunction,\n} from \"../core/types/common.js\";\nimport type { WriteContext } from \"./writeToStore.js\";\n\nimport {\n keyArgsFnFromSpecifier,\n keyFieldsFnFromSpecifier,\n} from \"./key-extractor.js\";\n\nexport type TypePolicies = {\n [__typename: string]: TypePolicy;\n};\n\n// TypeScript 3.7 will allow recursive type aliases, so this should work:\n// type KeySpecifier = (string | KeySpecifier)[]\nexport type KeySpecifier = ReadonlyArray<string | KeySpecifier>;\n\nexport type KeyFieldsContext = {\n // The __typename of the incoming object, even if the __typename field was\n // aliased to another name in the raw result object. May be undefined when\n // dataIdFromObject is called for objects without __typename fields.\n typename: string | undefined;\n\n // The object to be identified, after processing to remove aliases and\n // normalize identifiable child objects with references.\n storeObject: StoreObject;\n\n // Handy tool for reading additional fields from context.storeObject, either\n // readField(\"fieldName\") to read storeObject[fieldName], or readField(\"name\",\n // objectOrReference) to read from another object or Reference. If you read a\n // field with a read function, that function will be invoked.\n readField: ReadFieldFunction;\n\n // If you are writing a custom keyFields function, and you plan to use the raw\n // result object passed as the first argument, you may also need access to the\n // selection set and available fragments for this object, just in case any\n // fields have aliases. Since this logic is tricky to get right, and these\n // context properties are not even always provided (for example, they are\n // omitted when calling cache.identify(object), where object is assumed to be\n // a StoreObject), we recommend you use context.storeObject (which has already\n // been de-aliased) and context.readField (which can read from references as\n // well as objects) instead of the raw result object in your keyFields\n // functions, or just rely on the internal implementation of keyFields:[...]\n // syntax to get these details right for you.\n selectionSet?: SelectionSetNode;\n fragmentMap?: FragmentMap;\n\n // Internal. May be set by the KeyFieldsFunction to report fields that were\n // involved in computing the ID. Never passed in by the caller.\n keyObject?: Record<string, any>;\n};\n\nexport type KeyFieldsFunction = (\n object: Readonly<StoreObject>,\n context: KeyFieldsContext\n) => KeySpecifier | false | ReturnType<IdGetter>;\n\ntype KeyFieldsResult = Exclude<ReturnType<KeyFieldsFunction>, KeySpecifier>;\n\n// TODO Should TypePolicy be a generic type, with a TObject or TEntity\n// type parameter?\nexport type TypePolicy = {\n // Allows defining the primary key fields for this type, either using an\n // array of field names or a function that returns an arbitrary string.\n keyFields?: KeySpecifier | KeyFieldsFunction | false;\n\n // Allows defining a merge function (or merge:true/false shorthand) to\n // be used for merging objects of this type wherever they appear, unless\n // the parent field also defines a merge function/boolean (that is,\n // parent field merge functions take precedence over type policy merge\n // functions). In many cases, defining merge:true for a given type\n // policy can save you from specifying merge:true for all the field\n // policies where that type might be encountered.\n merge?: FieldMergeFunction | boolean;\n\n // In the rare event that your schema happens to use a different\n // __typename for the root Query, Mutation, and/or Schema types, you can\n // express your deviant preferences by enabling one of these options.\n queryType?: true;\n mutationType?: true;\n subscriptionType?: true;\n\n fields?: {\n [fieldName: string]: FieldPolicy<any> | FieldReadFunction<any>;\n };\n};\n\nexport type KeyArgsFunction = (\n args: Record<string, any> | null,\n context: {\n typename: string;\n fieldName: string;\n field: FieldNode | null;\n variables?: Record<string, any>;\n }\n) => KeySpecifier | false | ReturnType<IdGetter>;\n\nexport type FieldPolicy<\n // The internal representation used to store the field's data in the\n // cache. Must be JSON-serializable if you plan to serialize the result\n // of cache.extract() using JSON.\n TExisting = any,\n // The type of the incoming parameter passed to the merge function,\n // typically matching the GraphQL response format, but with Reference\n // objects substituted for any identifiable child objects. Often the\n // same as TExisting, but not necessarily.\n TIncoming = TExisting,\n // The type that the read function actually returns, using TExisting\n // data and options.args as input. Usually the same as TIncoming.\n TReadResult = TIncoming,\n // Allows FieldFunctionOptions definition to be overwritten by the\n // developer\n TOptions extends FieldFunctionOptions = FieldFunctionOptions,\n> = {\n keyArgs?: KeySpecifier | KeyArgsFunction | false;\n read?: FieldReadFunction<TExisting, TReadResult, TOptions>;\n merge?: FieldMergeFunction<TExisting, TIncoming, TOptions> | boolean;\n};\n\nexport type StorageType = Record<string, any>;\n\nfunction argsFromFieldSpecifier(spec: FieldSpecifier) {\n return (\n spec.args !== void 0 ? spec.args\n : spec.field ? argumentsObjectFromField(spec.field, spec.variables)\n : null\n );\n}\n\nexport interface FieldFunctionOptions<\n TArgs = Record<string, any>,\n TVars = Record<string, any>,\n> {\n args: TArgs | null;\n\n // The name of the field, equal to options.field.name.value when\n // options.field is available. Useful if you reuse the same function for\n // multiple fields, and you need to know which field you're currently\n // processing. Always a string, even when options.field is null.\n fieldName: string;\n\n // The full field key used internally, including serialized key arguments.\n storeFieldName: string;\n\n // The FieldNode object used to read this field. Useful if you need to\n // know about other attributes of the field, such as its directives. This\n // option will be null when a string was passed to options.readField.\n field: FieldNode | null;\n\n variables?: TVars;\n\n // Utilities for dealing with { __ref } objects.\n isReference: typeof isReference;\n toReference: ToReferenceFunction;\n\n // A handy place to put field-specific data that you want to survive\n // across multiple read function calls. Useful for field-level caching,\n // if your read function does any expensive work.\n storage: StorageType;\n\n cache: InMemoryCache;\n\n // Helper function for reading other fields within the current object.\n // If a foreign object or reference is provided, the field will be read\n // from that object instead of the current object, so this function can\n // be used (together with isReference) to examine the cache outside the\n // current object. If a FieldNode is passed instead of a string, and\n // that FieldNode has arguments, the same options.variables will be used\n // to compute the argument values. Note that this function will invoke\n // custom read functions for other fields, if defined. Always returns\n // immutable data (enforced with Object.freeze in development).\n readField: ReadFieldFunction;\n\n // Returns true for non-normalized StoreObjects and non-dangling\n // References, indicating that readField(name, objOrRef) has a chance of\n // working. Useful for filtering out dangling references from lists.\n canRead: CanReadFunction;\n\n // Instead of just merging objects with { ...existing, ...incoming }, this\n // helper function can be used to merge objects in a way that respects any\n // custom merge functions defined for their fields.\n mergeObjects: MergeObjectsFunction;\n}\n\ntype MergeObjectsFunction = <T extends StoreObject | Reference>(\n existing: T,\n incoming: T\n) => T;\n\nexport type FieldReadFunction<\n TExisting = any,\n TReadResult = TExisting,\n TOptions extends FieldFunctionOptions = FieldFunctionOptions,\n> = (\n // When reading a field, one often needs to know about any existing\n // value stored for that field. If the field is read before any value\n // has been written to the cache, this existing parameter will be\n // undefined, which makes it easy to use a default parameter expression\n // to supply the initial value. This parameter is positional (rather\n // than one of the named options) because that makes it possible for the\n // developer to annotate it with a type, without also having to provide\n // a whole new type for the options object.\n existing: SafeReadonly<TExisting> | undefined,\n options: TOptions\n) => TReadResult | undefined;\n\nexport type FieldMergeFunction<\n TExisting = any,\n TIncoming = TExisting,\n // Passing the whole FieldFunctionOptions makes the current definition\n // independent from its implementation\n TOptions extends FieldFunctionOptions = FieldFunctionOptions,\n> = (\n existing: SafeReadonly<TExisting> | undefined,\n // The incoming parameter needs to be positional as well, for the same\n // reasons discussed in FieldReadFunction above.\n incoming: SafeReadonly<TIncoming>,\n options: TOptions\n) => SafeReadonly<TExisting>;\n\nconst nullKeyFieldsFn: KeyFieldsFunction = () => void 0;\nconst simpleKeyArgsFn: KeyArgsFunction = (_args, context) => context.fieldName;\n\n// These merge functions can be selected by specifying merge:true or\n// merge:false in a field policy.\nconst mergeTrueFn: FieldMergeFunction<any> = (\n existing,\n incoming,\n { mergeObjects }\n) => mergeObjects(existing, incoming);\nconst mergeFalseFn: FieldMergeFunction<any> = (_, incoming) => incoming;\n\nexport type PossibleTypesMap = {\n [supertype: string]: string[];\n};\n\nexport class Policies {\n private typePolicies: {\n [__typename: string]: {\n keyFn?: KeyFieldsFunction;\n merge?: FieldMergeFunction<any>;\n fields: {\n [fieldName: string]: {\n keyFn?: KeyArgsFunction;\n read?: FieldReadFunction<any>;\n merge?: FieldMergeFunction<any>;\n };\n };\n };\n } = Object.create(null);\n\n private toBeAdded: {\n [__typename: string]: TypePolicy[];\n } = Object.create(null);\n\n // Map from subtype names to sets of supertype names. Note that this\n // representation inverts the structure of possibleTypes (whose keys are\n // supertypes and whose values are arrays of subtypes) because it tends\n // to be much more efficient to search upwards than downwards.\n private supertypeMap = new Map<string, Set<string>>();\n\n // Any fuzzy subtypes specified by possibleTypes will be converted to\n // RegExp objects and recorded here. Every key of this map can also be\n // found in supertypeMap. In many cases this Map will be empty, which\n // means no fuzzy subtype checking will happen in fragmentMatches.\n private fuzzySubtypes = new Map<string, RegExp>();\n\n public readonly cache: InMemoryCache;\n\n public readonly rootIdsByTypename: Record<string, string> =\n Object.create(null);\n public readonly rootTypenamesById: Record<string, string> =\n Object.create(null);\n\n public readonly usingPossibleTypes = false;\n\n constructor(\n private config: {\n cache: InMemoryCache;\n dataIdFromObject?: KeyFieldsFunction;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n }\n ) {\n this.config = {\n dataIdFromObject: defaultDataIdFromObject,\n ...config,\n };\n\n this.cache = this.config.cache;\n\n this.setRootTypename(\"Query\");\n this.setRootTypename(\"Mutation\");\n this.setRootTypename(\"Subscription\");\n\n if (config.possibleTypes) {\n this.addPossibleTypes(config.possibleTypes);\n }\n\n if (config.typePolicies) {\n this.addTypePolicies(config.typePolicies);\n }\n }\n\n public identify(\n object: StoreObject,\n partialContext?: Partial<KeyFieldsContext>\n ): [string?, StoreObject?] {\n const policies = this;\n\n const typename =\n (partialContext &&\n (partialContext.typename || partialContext.storeObject?.__typename)) ||\n object.__typename;\n\n // It should be possible to write root Query fields with writeFragment,\n // using { __typename: \"Query\", ... } as the data, but it does not make\n // sense to allow the same identification behavior for the Mutation and\n // Subscription types, since application code should never be writing\n // directly to (or reading directly from) those root objects.\n if (typename === this.rootTypenamesById.ROOT_QUERY) {\n return [\"ROOT_QUERY\"];\n }\n\n // Default context.storeObject to object if not otherwise provided.\n const storeObject =\n (partialContext && partialContext.storeObject) || object;\n\n const context: KeyFieldsContext = {\n ...partialContext,\n typename,\n storeObject,\n readField:\n (partialContext && partialContext.readField) ||\n function () {\n const options = normalizeReadFieldOptions(arguments, storeObject);\n return policies.readField(options, {\n store: policies.cache[\"data\"],\n variables: options.variables,\n });\n },\n };\n\n let id: KeyFieldsResult;\n\n const policy = typename && this.getTypePolicy(typename);\n let keyFn = (policy && policy.keyFn) || this.config.dataIdFromObject;\n while (keyFn) {\n const specifierOrId = keyFn({ ...object, ...storeObject }, context);\n if (isArray(specifierOrId)) {\n keyFn = keyFieldsFnFromSpecifier(specifierOrId);\n } else {\n id = specifierOrId;\n break;\n }\n }\n\n id = id ? String(id) : void 0;\n return context.keyObject ? [id, context.keyObject] : [id];\n }\n\n public addTypePolicies(typePolicies: TypePolicies) {\n Object.keys(typePolicies).forEach((typename) => {\n const { queryType, mutationType, subscriptionType, ...incoming } =\n typePolicies[typename];\n\n // Though {query,mutation,subscription}Type configurations are rare,\n // it's important to call setRootTypename as early as possible,\n // since these configurations should apply consistently for the\n // entire lifetime of the cache. Also, since only one __typename can\n // qualify as one of these root types, these three properties cannot\n // be inherited, unlike the rest of the incoming properties. That\n // restriction is convenient, because the purpose of this.toBeAdded\n // is to delay the processing of type/field policies until the first\n // time they're used, allowing policies to be added in any order as\n // long as all relevant policies (including policies for supertypes)\n // have been added by the time a given policy is used for the first\n // time. In other words, since inheritance doesn't matter for these\n // properties, there's also no need to delay their processing using\n // the this.toBeAdded queue.\n if (queryType) this.setRootTypename(\"Query\", typename);\n if (mutationType) this.setRootTypename(\"Mutation\", typename);\n if (subscriptionType) this.setRootTypename(\"Subscription\", typename);\n\n if (hasOwn.call(this.toBeAdded, typename)) {\n this.toBeAdded[typename].push(incoming);\n } else {\n this.toBeAdded[typename] = [incoming];\n }\n });\n }\n\n private updateTypePolicy(typename: string, incoming: TypePolicy) {\n const existing = this.getTypePolicy(typename);\n const { keyFields, fields } = incoming;\n\n function setMerge(\n existing: { merge?: FieldMergeFunction | boolean },\n merge?: FieldMergeFunction | boolean\n ) {\n existing.merge =\n typeof merge === \"function\" ? merge\n // Pass merge:true as a shorthand for a merge implementation\n // that returns options.mergeObjects(existing, incoming).\n : merge === true ? mergeTrueFn\n // Pass merge:false to make incoming always replace existing\n // without any warnings about data clobbering.\n : merge === false ? mergeFalseFn\n : existing.merge;\n }\n\n // Type policies can define merge functions, as an alternative to\n // using field policies to merge child objects.\n setMerge(existing, incoming.merge);\n\n existing.keyFn =\n // Pass false to disable normalization for this typename.\n keyFields === false ? nullKeyFieldsFn\n // Pass an array of strings to use those fields to compute a\n // composite ID for objects of this typename.\n : isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields)\n // Pass a function to take full control over identification.\n : typeof keyFields === \"function\" ? keyFields\n // Leave existing.keyFn unchanged if above cases fail.\n : existing.keyFn;\n\n if (fields) {\n Object.keys(fields).forEach((fieldName) => {\n const existing = this.getFieldPolicy(typename, fieldName, true)!;\n const incoming = fields[fieldName];\n\n if (typeof incoming === \"function\") {\n existing.read = incoming;\n } else {\n const { keyArgs, read, merge } = incoming;\n\n existing.keyFn =\n // Pass false to disable argument-based differentiation of\n // field identities.\n keyArgs === false ? simpleKeyArgsFn\n // Pass an array of strings to use named arguments to\n // compute a composite identity for the field.\n : isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs)\n // Pass a function to take full control over field identity.\n : typeof keyArgs === \"function\" ? keyArgs\n // Leave existing.keyFn unchanged if above cases fail.\n : existing.keyFn;\n\n if (typeof read === \"function\") {\n existing.read = read;\n }\n\n setMerge(existing, merge);\n }\n\n if (existing.read && existing.merge) {\n // If we have both a read and a merge function, assume\n // keyArgs:false, because read and merge together can take\n // responsibility for interpreting arguments in and out. This\n // default assumption can always be overridden by specifying\n // keyArgs explicitly in the FieldPolicy.\n existing.keyFn = existing.keyFn || simpleKeyArgsFn;\n }\n });\n }\n }\n\n private setRootTypename(\n which: \"Query\" | \"Mutation\" | \"Subscription\",\n typename: string = which\n ) {\n const rootId = \"ROOT_\" + which.toUpperCase();\n const old = this.rootTypenamesById[rootId];\n if (typename !== old) {\n invariant(\n !old || old === which,\n `Cannot change root %s __typename more than once`,\n which\n );\n // First, delete any old __typename associated with this rootId from\n // rootIdsByTypename.\n if (old) delete this.rootIdsByTypename[old];\n // Now make this the only __typename that maps to this rootId.\n this.rootIdsByTypename[typename] = rootId;\n // Finally, update the __typename associated with this rootId.\n this.rootTypenamesById[rootId] = typename;\n }\n }\n\n public addPossibleTypes(possibleTypes: PossibleTypesMap) {\n (this.usingPossibleTypes as boolean) = true;\n Object.keys(possibleTypes).forEach((supertype) => {\n // Make sure all types have an entry in this.supertypeMap, even if\n // their supertype set is empty, so we can return false immediately\n // from policies.fragmentMatches for unknown supertypes.\n this.getSupertypeSet(supertype, true);\n\n possibleTypes[supertype].forEach((subtype) => {\n this.getSupertypeSet(subtype, true)!.add(supertype);\n const match = subtype.match(TypeOrFieldNameRegExp);\n if (!match || match[0] !== subtype) {\n // TODO Don't interpret just any invalid typename as a RegExp.\n this.fuzzySubtypes.set(subtype, new RegExp(subtype));\n }\n });\n });\n }\n\n private getTypePolicy(typename: string): Policies[\"typePolicies\"][string] {\n if (!hasOwn.call(this.typePolicies, typename)) {\n const policy: Policies[\"typePolicies\"][string] = (this.typePolicies[\n typename\n ] = Object.create(null));\n policy.fields = Object.create(null);\n\n // When the TypePolicy for typename is first accessed, instead of\n // starting with an empty policy object, inherit any properties or\n // fields from the type policies of the supertypes of typename.\n //\n // Any properties or fields defined explicitly within the TypePolicy\n // for typename will take precedence, and if there are multiple\n // supertypes, the properties of policies whose types were added\n // later via addPossibleTypes will take precedence over those of\n // earlier supertypes. TODO Perhaps we should warn about these\n // conflicts in development, and recommend defining the property\n // explicitly in the subtype policy?\n //\n // Field policy inheritance is atomic/shallow: you can't inherit a\n // field policy and then override just its read function, since read\n // and merge functions often need to cooperate, so changing only one\n // of them would be a recipe for inconsistency.\n //\n // Once the TypePolicy for typename has been accessed, its properties can\n // still be updated directly using addTypePolicies, but future changes to\n // inherited supertype policies will not be reflected in this subtype\n // policy, because this code runs at most once per typename.\n let supertypes = this.supertypeMap.get(typename);\n if (!supertypes && this.fuzzySubtypes.size) {\n // To make the inheritance logic work for unknown typename strings that\n // may have fuzzy supertypes, we give this typename an empty supertype\n // set and then populate it with any fuzzy supertypes that match.\n supertypes = this.getSupertypeSet(typename, true)!;\n // This only works for typenames that are directly matched by a fuzzy\n // supertype. What if there is an intermediate chain of supertypes?\n // While possible, that situation can only be solved effectively by\n // specifying the intermediate relationships via possibleTypes, manually\n // and in a non-fuzzy way.\n this.fuzzySubtypes.forEach((regExp, fuzzy) => {\n if (regExp.test(typename)) {\n // The fuzzy parameter is just the original string version of regExp\n // (not a valid __typename string), but we can look up the\n // associated supertype(s) in this.supertypeMap.\n const fuzzySupertypes = this.supertypeMap.get(fuzzy);\n if (fuzzySupertypes) {\n fuzzySupertypes.forEach((supertype) =>\n supertypes!.add(supertype)\n );\n }\n }\n });\n }\n if (supertypes && supertypes.size) {\n supertypes.forEach((supertype) => {\n const { fields, ...rest } = this.getTypePolicy(supertype);\n Object.assign(policy, rest);\n Object.assign(policy.fields, fields);\n });\n }\n }\n\n const inbox = this.toBeAdded[typename];\n if (inbox && inbox.length) {\n // Merge the pending policies into this.typePolicies, in the order they\n // were originally passed to addTypePolicy.\n inbox.splice(0).forEach((policy) => {\n this.updateTypePolicy(typename, policy);\n });\n }\n\n return this.typePolicies[typename];\n }\n\n private getFieldPolicy(\n typename: string | undefined,\n fieldName: string,\n createIfMissing: boolean\n ):\n | {\n keyFn?: KeyArgsFunction;\n read?: FieldReadFunction<any>;\n merge?: FieldMergeFunction<any>;\n }\n | undefined {\n if (typename) {\n const fieldPolicies = this.getTypePolicy(typename).fields;\n return (\n fieldPolicies[fieldName] ||\n (createIfMissing && (fieldPolicies[fieldName] = Object.create(null)))\n );\n }\n }\n\n private getSupertypeSet(\n subtype: string,\n createIfMissing: boolean\n ): Set<string> | undefined {\n let supertypeSet = this.supertypeMap.get(subtype);\n if (!supertypeSet && createIfMissing) {\n this.supertypeMap.set(subtype, (supertypeSet = new Set<string>()));\n }\n return supertypeSet;\n }\n\n public fragmentMatches(\n fragment: InlineFragmentNode | FragmentDefinitionNode,\n typename: string | undefined,\n result?: Record<string, any>,\n variables?: Record<string, any>\n ): boolean {\n if (!fragment.typeCondition) return true;\n\n // If the fragment has a type condition but the object we're matching\n // against does not have a __typename, the fragment cannot match.\n if (!typename) return false;\n\n const supertype = fragment.typeCondition.name.value;\n // Common case: fragment type condition and __typename are the same.\n if (typename === supertype) return true;\n\n if (this.usingPossibleTypes && this.supertypeMap.has(supertype)) {\n const typenameSupertypeSet = this.getSupertypeSet(typename, true)!;\n const workQueue = [typenameSupertypeSet];\n const maybeEnqueue = (subtype: string) => {\n const supertypeSet = this.getSupertypeSet(subtype, false);\n if (\n supertypeSet &&\n supertypeSet.size &&\n workQueue.indexOf(supertypeSet) < 0\n ) {\n workQueue.push(supertypeSet);\n }\n };\n\n // We need to check fuzzy subtypes only if we encountered fuzzy\n // subtype strings in addPossibleTypes, and only while writing to\n // the cache, since that's when selectionSetMatchesResult gives a\n // strong signal of fragment matching. The StoreReader class calls\n // policies.fragmentMatches without passing a result object, so\n // needToCheckFuzzySubtypes is always false while reading.\n let needToCheckFuzzySubtypes = !!(result && this.fuzzySubtypes.size);\n let checkingFuzzySubtypes = false;\n\n // It's important to keep evaluating workQueue.length each time through\n // the loop, because the queue can grow while we're iterating over it.\n for (let i = 0; i < workQueue.length; ++i) {\n const supertypeSet = workQueue[i];\n\n if (supertypeSet.has(supertype)) {\n if (!typenameSupertypeSet.has(supertype)) {\n if (checkingFuzzySubtypes) {\n invariant.warn(\n `Inferring subtype %s of supertype %s`,\n typename,\n supertype\n );\n }\n // Record positive results for faster future lookup.\n // Unfortunately, we cannot safely cache negative results,\n // because new possibleTypes data could always be added to the\n // Policies class.\n typenameSupertypeSet.add(supertype);\n }\n return true;\n }\n\n supertypeSet.forEach(maybeEnqueue);\n\n if (\n needToCheckFuzzySubtypes &&\n // Start checking fuzzy subtypes only after exhausting all\n // non-fuzzy subtypes (after the final iteration of the loop).\n i === workQueue.length - 1 &&\n // We could wait to compare fragment.selectionSet to result\n // after we verify the supertype, but this check is often less\n // expensive than that search, and we will have to do the\n // comparison anyway whenever we find a potential match.\n selectionSetMatchesResult(fragment.selectionSet, result!, variables)\n ) {\n // We don't always need to check fuzzy subtypes (if no result\n // was provided, or !this.fuzzySubtypes.size), but, when we do,\n // we only want to check them once.\n needToCheckFuzzySubtypes = false;\n checkingFuzzySubtypes = true;\n\n // If we find any fuzzy subtypes that match typename, extend the\n // workQueue to search through the supertypes of those fuzzy\n // subtypes. Otherwise the for-loop will terminate and we'll\n // return false below.\n this.fuzzySubtypes.forEach((regExp, fuzzyString) => {\n const match = typename.match(regExp);\n if (match && match[0] === typename) {\n maybeEnqueue(fuzzyString);\n }\n });\n }\n }\n }\n\n return false;\n }\n\n public hasKeyArgs(typename: string | undefined, fieldName: string) {\n const policy = this.getFieldPolicy(typename, fieldName, false);\n return !!(policy && policy.keyFn);\n }\n\n public getStoreFieldName(fieldSpec: FieldSpecifier): string {\n const { typename, fieldName } = fieldSpec;\n const policy = this.getFieldPolicy(typename, fieldName, false);\n let storeFieldName: Exclude<ReturnType<KeyArgsFunction>, KeySpecifier>;\n\n let keyFn = policy && policy.keyFn;\n if (keyFn && typename) {\n const context: Parameters<KeyArgsFunction>[1] = {\n typename,\n fieldName,\n field: fieldSpec.field || null,\n variables: fieldSpec.variables,\n };\n const args = argsFromFieldSpecifier(fieldSpec);\n while (keyFn) {\n const specifierOrString = keyFn(args, context);\n if (isArray(specifierOrString)) {\n keyFn = keyArgsFnFromSpecifier(specifierOrString);\n } else {\n // If the custom keyFn returns a falsy value, fall back to\n // fieldName instead.\n storeFieldName = specifierOrString || fieldName;\n break;\n }\n }\n }\n\n if (storeFieldName === void 0) {\n storeFieldName =\n fieldSpec.field ?\n storeKeyNameFromField(fieldSpec.field, fieldSpec.variables)\n : getStoreKeyName(fieldName, argsFromFieldSpecifier(fieldSpec));\n }\n\n // Returning false from a keyArgs function is like configuring\n // keyArgs: false, but more dynamic.\n if (storeFieldName === false) {\n return fieldName;\n }\n\n // Make sure custom field names start with the actual field.name.value\n // of the field, so we can always figure out which properties of a\n // StoreObject correspond to which original field names.\n return fieldName === fieldNameFromStoreName(storeFieldName) ? storeFieldName\n : fieldName + \":\" + storeFieldName;\n }\n\n public readField<V = StoreValue>(\n options: ReadFieldOptions,\n context: ReadMergeModifyContext\n ): SafeReadonly<V> | undefined {\n const objectOrReference = options.from;\n if (!objectOrReference) return;\n\n const nameOrField = options.field || options.fieldName;\n if (!nameOrField) return;\n\n if (options.typename === void 0) {\n const typename = context.store.getFieldValue<string>(\n objectOrReference,\n \"__typename\"\n );\n if (typename) options.typename = typename;\n }\n\n const storeFieldName = this.getStoreFieldName(options);\n const fieldName = fieldNameFromStoreName(storeFieldName);\n const existing = context.store.getFieldValue<V>(\n objectOrReference,\n storeFieldName\n );\n const policy = this.getFieldPolicy(options.typename, fieldName, false);\n const read = policy && policy.read;\n\n if (read) {\n const readOptions = makeFieldFunctionOptions(\n this,\n objectOrReference,\n options,\n context,\n context.store.getStorage(\n isReference(objectOrReference) ?\n objectOrReference.__ref\n : objectOrReference,\n storeFieldName\n )\n );\n\n // Call read(existing, readOptions) with cacheSlot holding this.cache.\n return cacheSlot.withValue(this.cache, read, [\n existing,\n readOptions,\n ]) as SafeReadonly<V>;\n }\n\n return existing;\n }\n\n public getReadFunction(\n typename: string | undefined,\n fieldName: string\n ): FieldReadFunction | undefined {\n const policy = this.getFieldPolicy(typename, fieldName, false);\n return policy && policy.read;\n }\n\n public getMergeFunction(\n parentTypename: string | undefined,\n fieldName: string,\n childTypename: string | undefined\n ): FieldMergeFunction | undefined {\n let policy:\n | Policies[\"typePolicies\"][string]\n | Policies[\"typePolicies\"][string][\"fields\"][string]\n | undefined = this.getFieldPolicy(parentTypename, fieldName, false);\n let merge = policy && policy.merge;\n if (!merge && childTypename) {\n policy = this.getTypePolicy(childTypename);\n merge = policy && policy.merge;\n }\n return merge;\n }\n\n public runMergeFunction(\n existing: StoreValue,\n incoming: StoreValue,\n { field, typename, merge }: MergeInfo,\n context: WriteContext,\n storage?: StorageType\n ) {\n if (merge === mergeTrueFn) {\n // Instead of going to the trouble of creating a full\n // FieldFunctionOptions object and calling mergeTrueFn, we can\n // simply call mergeObjects, as mergeTrueFn would.\n return makeMergeObjectsFunction(context.store)(\n existing as StoreObject,\n incoming as StoreObject\n );\n }\n\n if (merge === mergeFalseFn) {\n // Likewise for mergeFalseFn, whose implementation is even simpler.\n return incoming;\n }\n\n // If cache.writeQuery or cache.writeFragment was called with\n // options.overwrite set to true, we still call merge functions, but\n // the existing data is always undefined, so the merge function will\n // not attempt to combine the incoming data with the existing data.\n if (context.overwrite) {\n existing = void 0;\n }\n\n return merge(\n existing,\n incoming,\n makeFieldFunctionOptions(\n this,\n // Unlike options.readField for read functions, we do not fall\n // back to the current object if no foreignObjOrRef is provided,\n // because it's not clear what the current object should be for\n // merge functions: the (possibly undefined) existing object, or\n // the incoming object? If you think your merge function needs\n // to read sibling fields in order to produce a new value for\n // the current field, you might want to rethink your strategy,\n // because that's a recipe for making merge behavior sensitive\n // to the order in which fields are written into the cache.\n // However, readField(name, ref) is useful for merge functions\n // that need to deduplicate child objects and references.\n void 0,\n {\n typename,\n fieldName: field.name.value,\n field,\n variables: context.variables,\n },\n context,\n storage || Object.create(null)\n )\n );\n }\n}\n\nfunction makeFieldFunctionOptions(\n policies: Policies,\n objectOrReference: StoreObject | Reference | undefined,\n fieldSpec: FieldSpecifier,\n context: ReadMergeModifyContext,\n storage: StorageType\n): FieldFunctionOptions {\n const storeFieldName = policies.getStoreFieldName(fieldSpec);\n const fieldName = fieldNameFromStoreName(storeFieldName);\n const variables = fieldSpec.variables || context.variables;\n const { toReference, canRead } = context.store;\n\n return {\n args: argsFromFieldSpecifier(fieldSpec),\n field: fieldSpec.field || null,\n fieldName,\n storeFieldName,\n variables,\n isReference,\n toReference,\n storage,\n cache: policies.cache,\n canRead,\n readField<T>() {\n return policies.readField<T>(\n normalizeReadFieldOptions(arguments, objectOrReference, variables),\n context\n );\n },\n mergeObjects: makeMergeObjectsFunction(context.store),\n };\n}\n\nexport function normalizeReadFieldOptions(\n readFieldArgs: IArguments,\n objectOrReference: StoreObject | Reference | undefined,\n variables?: ReadMergeModifyContext[\"variables\"]\n): ReadFieldOptions {\n const { 0: fieldNameOrOptions, 1: from, length: argc } = readFieldArgs;\n\n let options: ReadFieldOptions;\n\n if (typeof fieldNameOrOptions === \"string\") {\n options = {\n fieldName: fieldNameOrOptions,\n // Default to objectOrReference only when no second argument was\n // passed for the from parameter, not when undefined is explicitly\n // passed as the second argument.\n from: argc > 1 ? from : objectOrReference,\n };\n } else {\n options = { ...fieldNameOrOptions };\n // Default to objectOrReference only when fieldNameOrOptions.from is\n // actually omitted, rather than just undefined.\n if (!hasOwn.call(options, \"from\")) {\n options.from = objectOrReference;\n }\n }\n\n if (__DEV__ && options.from === void 0) {\n invariant.warn(\n `Undefined 'from' passed to readField with arguments %s`,\n stringifyForDisplay(Array.from(readFieldArgs))\n );\n }\n\n if (void 0 === options.variables) {\n options.variables = variables;\n }\n\n return options;\n}\n\nfunction makeMergeObjectsFunction(\n store: NormalizedCache\n): MergeObjectsFunction {\n return function mergeObjects(existing, incoming) {\n if (isArray(existing) || isArray(incoming)) {\n throw newInvariantError(\"Cannot automatically merge arrays\");\n }\n\n // These dynamic checks are necessary because the parameters of a\n // custom merge function can easily have the any type, so the type\n // system cannot always enforce the StoreObject | Reference parameter\n // types of options.mergeObjects.\n if (isNonNullObject(existing) && isNonNullObject(incoming)) {\n const eType = store.getFieldValue(existing, \"__typename\");\n const iType = store.getFieldValue(incoming, \"__typename\");\n const typesDiffer = eType && iType && eType !== iType;\n\n if (typesDiffer) {\n return incoming;\n }\n\n if (isReference(existing) && storeValueIsStoreObject(incoming)) {\n // Update the normalized EntityStore for the entity identified by\n // existing.__ref, preferring/overwriting any fields contributed by the\n // newer incoming StoreObject.\n store.merge(existing.__ref, incoming);\n return existing;\n }\n\n if (storeValueIsStoreObject(existing) && isReference(incoming)) {\n // Update the normalized EntityStore for the entity identified by\n // incoming.__ref, taking fields from the older existing object only if\n // those fields are not already present in the newer StoreObject\n // identified by incoming.__ref.\n store.merge(existing, incoming.__ref);\n return incoming;\n }\n\n if (\n storeValueIsStoreObject(existing) &&\n storeValueIsStoreObject(incoming)\n ) {\n return { ...existing, ...incoming };\n }\n }\n\n return incoming;\n };\n}\n"]}
1
+ {"version":3,"file":"policies.js","sourceRoot":"","sources":["../../../src/cache/inmemory/policies.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAehF,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,WAAW,EACX,eAAe,EACf,eAAe,EACf,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EACL,MAAM,EACN,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,q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SelectionSetNode,\n FieldNode,\n} from \"graphql\";\n\nimport type {\n FragmentMap,\n StoreValue,\n StoreObject,\n Reference,\n} from \"../../utilities/index.js\";\nimport {\n storeKeyNameFromField,\n argumentsObjectFromField,\n isReference,\n getStoreKeyName,\n isNonNullObject,\n stringifyForDisplay,\n} from \"../../utilities/index.js\";\nimport type {\n IdGetter,\n MergeInfo,\n NormalizedCache,\n ReadMergeModifyContext,\n} from \"./types.js\";\nimport {\n hasOwn,\n fieldNameFromStoreName,\n storeValueIsStoreObject,\n selectionSetMatchesResult,\n TypeOrFieldNameRegExp,\n defaultDataIdFromObject,\n isArray,\n} from \"./helpers.js\";\nimport { cacheSlot } from \"./reactiveVars.js\";\nimport type { InMemoryCache } from \"./inMemoryCache.js\";\nimport type {\n SafeReadonly,\n FieldSpecifier,\n ToReferenceFunction,\n ReadFieldFunction,\n ReadFieldOptions,\n CanReadFunction,\n} from \"../core/types/common.js\";\nimport type { WriteContext } from \"./writeToStore.js\";\n\nimport {\n keyArgsFnFromSpecifier,\n keyFieldsFnFromSpecifier,\n} from \"./key-extractor.js\";\nimport { disableWarningsSlot } from \"../../core/masking.js\";\n\nexport type TypePolicies = {\n [__typename: string]: TypePolicy;\n};\n\n// TypeScript 3.7 will allow recursive type aliases, so this should work:\n// type KeySpecifier = (string | KeySpecifier)[]\nexport type KeySpecifier = ReadonlyArray<string | KeySpecifier>;\n\nexport type KeyFieldsContext = {\n // The __typename of the incoming object, even if the __typename field was\n // aliased to another name in the raw result object. May be undefined when\n // dataIdFromObject is called for objects without __typename fields.\n typename: string | undefined;\n\n // The object to be identified, after processing to remove aliases and\n // normalize identifiable child objects with references.\n storeObject: StoreObject;\n\n // Handy tool for reading additional fields from context.storeObject, either\n // readField(\"fieldName\") to read storeObject[fieldName], or readField(\"name\",\n // objectOrReference) to read from another object or Reference. If you read a\n // field with a read function, that function will be invoked.\n readField: ReadFieldFunction;\n\n // If you are writing a custom keyFields function, and you plan to use the raw\n // result object passed as the first argument, you may also need access to the\n // selection set and available fragments for this object, just in case any\n // fields have aliases. Since this logic is tricky to get right, and these\n // context properties are not even always provided (for example, they are\n // omitted when calling cache.identify(object), where object is assumed to be\n // a StoreObject), we recommend you use context.storeObject (which has already\n // been de-aliased) and context.readField (which can read from references as\n // well as objects) instead of the raw result object in your keyFields\n // functions, or just rely on the internal implementation of keyFields:[...]\n // syntax to get these details right for you.\n selectionSet?: SelectionSetNode;\n fragmentMap?: FragmentMap;\n\n // Internal. May be set by the KeyFieldsFunction to report fields that were\n // involved in computing the ID. Never passed in by the caller.\n keyObject?: Record<string, any>;\n};\n\nexport type KeyFieldsFunction = (\n object: Readonly<StoreObject>,\n context: KeyFieldsContext\n) => KeySpecifier | false | ReturnType<IdGetter>;\n\ntype KeyFieldsResult = Exclude<ReturnType<KeyFieldsFunction>, KeySpecifier>;\n\n// TODO Should TypePolicy be a generic type, with a TObject or TEntity\n// type parameter?\nexport type TypePolicy = {\n // Allows defining the primary key fields for this type, either using an\n // array of field names or a function that returns an arbitrary string.\n keyFields?: KeySpecifier | KeyFieldsFunction | false;\n\n // Allows defining a merge function (or merge:true/false shorthand) to\n // be used for merging objects of this type wherever they appear, unless\n // the parent field also defines a merge function/boolean (that is,\n // parent field merge functions take precedence over type policy merge\n // functions). In many cases, defining merge:true for a given type\n // policy can save you from specifying merge:true for all the field\n // policies where that type might be encountered.\n merge?: FieldMergeFunction | boolean;\n\n // In the rare event that your schema happens to use a different\n // __typename for the root Query, Mutation, and/or Schema types, you can\n // express your deviant preferences by enabling one of these options.\n queryType?: true;\n mutationType?: true;\n subscriptionType?: true;\n\n fields?: {\n [fieldName: string]: FieldPolicy<any> | FieldReadFunction<any>;\n };\n};\n\nexport type KeyArgsFunction = (\n args: Record<string, any> | null,\n context: {\n typename: string;\n fieldName: string;\n field: FieldNode | null;\n variables?: Record<string, any>;\n }\n) => KeySpecifier | false | ReturnType<IdGetter>;\n\nexport type FieldPolicy<\n // The internal representation used to store the field's data in the\n // cache. Must be JSON-serializable if you plan to serialize the result\n // of cache.extract() using JSON.\n TExisting = any,\n // The type of the incoming parameter passed to the merge function,\n // typically matching the GraphQL response format, but with Reference\n // objects substituted for any identifiable child objects. Often the\n // same as TExisting, but not necessarily.\n TIncoming = TExisting,\n // The type that the read function actually returns, using TExisting\n // data and options.args as input. Usually the same as TIncoming.\n TReadResult = TIncoming,\n // Allows FieldFunctionOptions definition to be overwritten by the\n // developer\n TOptions extends FieldFunctionOptions = FieldFunctionOptions,\n> = {\n keyArgs?: KeySpecifier | KeyArgsFunction | false;\n read?: FieldReadFunction<TExisting, TReadResult, TOptions>;\n merge?: FieldMergeFunction<TExisting, TIncoming, TOptions> | boolean;\n};\n\nexport type StorageType = Record<string, any>;\n\nfunction argsFromFieldSpecifier(spec: FieldSpecifier) {\n return (\n spec.args !== void 0 ? spec.args\n : spec.field ? argumentsObjectFromField(spec.field, spec.variables)\n : null\n );\n}\n\nexport interface FieldFunctionOptions<\n TArgs = Record<string, any>,\n TVars = Record<string, any>,\n> {\n args: TArgs | null;\n\n // The name of the field, equal to options.field.name.value when\n // options.field is available. Useful if you reuse the same function for\n // multiple fields, and you need to know which field you're currently\n // processing. Always a string, even when options.field is null.\n fieldName: string;\n\n // The full field key used internally, including serialized key arguments.\n storeFieldName: string;\n\n // The FieldNode object used to read this field. Useful if you need to\n // know about other attributes of the field, such as its directives. This\n // option will be null when a string was passed to options.readField.\n field: FieldNode | null;\n\n variables?: TVars;\n\n // Utilities for dealing with { __ref } objects.\n isReference: typeof isReference;\n toReference: ToReferenceFunction;\n\n // A handy place to put field-specific data that you want to survive\n // across multiple read function calls. Useful for field-level caching,\n // if your read function does any expensive work.\n storage: StorageType;\n\n cache: InMemoryCache;\n\n // Helper function for reading other fields within the current object.\n // If a foreign object or reference is provided, the field will be read\n // from that object instead of the current object, so this function can\n // be used (together with isReference) to examine the cache outside the\n // current object. If a FieldNode is passed instead of a string, and\n // that FieldNode has arguments, the same options.variables will be used\n // to compute the argument values. Note that this function will invoke\n // custom read functions for other fields, if defined. Always returns\n // immutable data (enforced with Object.freeze in development).\n readField: ReadFieldFunction;\n\n // Returns true for non-normalized StoreObjects and non-dangling\n // References, indicating that readField(name, objOrRef) has a chance of\n // working. Useful for filtering out dangling references from lists.\n canRead: CanReadFunction;\n\n // Instead of just merging objects with { ...existing, ...incoming }, this\n // helper function can be used to merge objects in a way that respects any\n // custom merge functions defined for their fields.\n mergeObjects: MergeObjectsFunction;\n}\n\ntype MergeObjectsFunction = <T extends StoreObject | Reference>(\n existing: T,\n incoming: T\n) => T;\n\nexport type FieldReadFunction<\n TExisting = any,\n TReadResult = TExisting,\n TOptions extends FieldFunctionOptions = FieldFunctionOptions,\n> = (\n // When reading a field, one often needs to know about any existing\n // value stored for that field. If the field is read before any value\n // has been written to the cache, this existing parameter will be\n // undefined, which makes it easy to use a default parameter expression\n // to supply the initial value. This parameter is positional (rather\n // than one of the named options) because that makes it possible for the\n // developer to annotate it with a type, without also having to provide\n // a whole new type for the options object.\n existing: SafeReadonly<TExisting> | undefined,\n options: TOptions\n) => TReadResult | undefined;\n\nexport type FieldMergeFunction<\n TExisting = any,\n TIncoming = TExisting,\n // Passing the whole FieldFunctionOptions makes the current definition\n // independent from its implementation\n TOptions extends FieldFunctionOptions = FieldFunctionOptions,\n> = (\n existing: SafeReadonly<TExisting> | undefined,\n // The incoming parameter needs to be positional as well, for the same\n // reasons discussed in FieldReadFunction above.\n incoming: SafeReadonly<TIncoming>,\n options: TOptions\n) => SafeReadonly<TExisting>;\n\nconst nullKeyFieldsFn: KeyFieldsFunction = () => void 0;\nconst simpleKeyArgsFn: KeyArgsFunction = (_args, context) => context.fieldName;\n\n// These merge functions can be selected by specifying merge:true or\n// merge:false in a field policy.\nconst mergeTrueFn: FieldMergeFunction<any> = (\n existing,\n incoming,\n { mergeObjects }\n) => mergeObjects(existing, incoming);\nconst mergeFalseFn: FieldMergeFunction<any> = (_, incoming) => incoming;\n\nexport type PossibleTypesMap = {\n [supertype: string]: string[];\n};\n\nexport class Policies {\n private typePolicies: {\n [__typename: string]: {\n keyFn?: KeyFieldsFunction;\n merge?: FieldMergeFunction<any>;\n fields: {\n [fieldName: string]: {\n keyFn?: KeyArgsFunction;\n read?: FieldReadFunction<any>;\n merge?: FieldMergeFunction<any>;\n };\n };\n };\n } = Object.create(null);\n\n private toBeAdded: {\n [__typename: string]: TypePolicy[];\n } = Object.create(null);\n\n // Map from subtype names to sets of supertype names. Note that this\n // representation inverts the structure of possibleTypes (whose keys are\n // supertypes and whose values are arrays of subtypes) because it tends\n // to be much more efficient to search upwards than downwards.\n private supertypeMap = new Map<string, Set<string>>();\n\n // Any fuzzy subtypes specified by possibleTypes will be converted to\n // RegExp objects and recorded here. Every key of this map can also be\n // found in supertypeMap. In many cases this Map will be empty, which\n // means no fuzzy subtype checking will happen in fragmentMatches.\n private fuzzySubtypes = new Map<string, RegExp>();\n\n public readonly cache: InMemoryCache;\n\n public readonly rootIdsByTypename: Record<string, string> =\n Object.create(null);\n public readonly rootTypenamesById: Record<string, string> =\n Object.create(null);\n\n public readonly usingPossibleTypes = false;\n\n constructor(\n private config: {\n cache: InMemoryCache;\n dataIdFromObject?: KeyFieldsFunction;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n }\n ) {\n this.config = {\n dataIdFromObject: defaultDataIdFromObject,\n ...config,\n };\n\n this.cache = this.config.cache;\n\n this.setRootTypename(\"Query\");\n this.setRootTypename(\"Mutation\");\n this.setRootTypename(\"Subscription\");\n\n if (config.possibleTypes) {\n this.addPossibleTypes(config.possibleTypes);\n }\n\n if (config.typePolicies) {\n this.addTypePolicies(config.typePolicies);\n }\n }\n\n public identify(\n object: StoreObject,\n partialContext?: Partial<KeyFieldsContext>\n ): [string?, StoreObject?] {\n const policies = this;\n\n const typename =\n (partialContext &&\n (partialContext.typename || partialContext.storeObject?.__typename)) ||\n object.__typename;\n\n // It should be possible to write root Query fields with writeFragment,\n // using { __typename: \"Query\", ... } as the data, but it does not make\n // sense to allow the same identification behavior for the Mutation and\n // Subscription types, since application code should never be writing\n // directly to (or reading directly from) those root objects.\n if (typename === this.rootTypenamesById.ROOT_QUERY) {\n return [\"ROOT_QUERY\"];\n }\n\n // Default context.storeObject to object if not otherwise provided.\n const storeObject =\n (partialContext && partialContext.storeObject) || object;\n\n const context: KeyFieldsContext = {\n ...partialContext,\n typename,\n storeObject,\n readField:\n (partialContext && partialContext.readField) ||\n function () {\n const options = normalizeReadFieldOptions(arguments, storeObject);\n return policies.readField(options, {\n store: policies.cache[\"data\"],\n variables: options.variables,\n });\n },\n };\n\n let id: KeyFieldsResult;\n\n const policy = typename && this.getTypePolicy(typename);\n let keyFn = (policy && policy.keyFn) || this.config.dataIdFromObject;\n\n disableWarningsSlot.withValue(true, () => {\n while (keyFn) {\n const specifierOrId = keyFn({ ...object, ...storeObject }, context);\n if (isArray(specifierOrId)) {\n keyFn = keyFieldsFnFromSpecifier(specifierOrId);\n } else {\n id = specifierOrId;\n break;\n }\n }\n });\n\n id = id ? String(id) : void 0;\n return context.keyObject ? [id, context.keyObject] : [id];\n }\n\n public addTypePolicies(typePolicies: TypePolicies) {\n Object.keys(typePolicies).forEach((typename) => {\n const { queryType, mutationType, subscriptionType, ...incoming } =\n typePolicies[typename];\n\n // Though {query,mutation,subscription}Type configurations are rare,\n // it's important to call setRootTypename as early as possible,\n // since these configurations should apply consistently for the\n // entire lifetime of the cache. Also, since only one __typename can\n // qualify as one of these root types, these three properties cannot\n // be inherited, unlike the rest of the incoming properties. That\n // restriction is convenient, because the purpose of this.toBeAdded\n // is to delay the processing of type/field policies until the first\n // time they're used, allowing policies to be added in any order as\n // long as all relevant policies (including policies for supertypes)\n // have been added by the time a given policy is used for the first\n // time. In other words, since inheritance doesn't matter for these\n // properties, there's also no need to delay their processing using\n // the this.toBeAdded queue.\n if (queryType) this.setRootTypename(\"Query\", typename);\n if (mutationType) this.setRootTypename(\"Mutation\", typename);\n if (subscriptionType) this.setRootTypename(\"Subscription\", typename);\n\n if (hasOwn.call(this.toBeAdded, typename)) {\n this.toBeAdded[typename].push(incoming);\n } else {\n this.toBeAdded[typename] = [incoming];\n }\n });\n }\n\n private updateTypePolicy(typename: string, incoming: TypePolicy) {\n const existing = this.getTypePolicy(typename);\n const { keyFields, fields } = incoming;\n\n function setMerge(\n existing: { merge?: FieldMergeFunction | boolean },\n merge?: FieldMergeFunction | boolean\n ) {\n existing.merge =\n typeof merge === \"function\" ? merge\n // Pass merge:true as a shorthand for a merge implementation\n // that returns options.mergeObjects(existing, incoming).\n : merge === true ? mergeTrueFn\n // Pass merge:false to make incoming always replace existing\n // without any warnings about data clobbering.\n : merge === false ? mergeFalseFn\n : existing.merge;\n }\n\n // Type policies can define merge functions, as an alternative to\n // using field policies to merge child objects.\n setMerge(existing, incoming.merge);\n\n existing.keyFn =\n // Pass false to disable normalization for this typename.\n keyFields === false ? nullKeyFieldsFn\n // Pass an array of strings to use those fields to compute a\n // composite ID for objects of this typename.\n : isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields)\n // Pass a function to take full control over identification.\n : typeof keyFields === \"function\" ? keyFields\n // Leave existing.keyFn unchanged if above cases fail.\n : existing.keyFn;\n\n if (fields) {\n Object.keys(fields).forEach((fieldName) => {\n const existing = this.getFieldPolicy(typename, fieldName, true)!;\n const incoming = fields[fieldName];\n\n if (typeof incoming === \"function\") {\n existing.read = incoming;\n } else {\n const { keyArgs, read, merge } = incoming;\n\n existing.keyFn =\n // Pass false to disable argument-based differentiation of\n // field identities.\n keyArgs === false ? simpleKeyArgsFn\n // Pass an array of strings to use named arguments to\n // compute a composite identity for the field.\n : isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs)\n // Pass a function to take full control over field identity.\n : typeof keyArgs === \"function\" ? keyArgs\n // Leave existing.keyFn unchanged if above cases fail.\n : existing.keyFn;\n\n if (typeof read === \"function\") {\n existing.read = read;\n }\n\n setMerge(existing, merge);\n }\n\n if (existing.read && existing.merge) {\n // If we have both a read and a merge function, assume\n // keyArgs:false, because read and merge together can take\n // responsibility for interpreting arguments in and out. This\n // default assumption can always be overridden by specifying\n // keyArgs explicitly in the FieldPolicy.\n existing.keyFn = existing.keyFn || simpleKeyArgsFn;\n }\n });\n }\n }\n\n private setRootTypename(\n which: \"Query\" | \"Mutation\" | \"Subscription\",\n typename: string = which\n ) {\n const rootId = \"ROOT_\" + which.toUpperCase();\n const old = this.rootTypenamesById[rootId];\n if (typename !== old) {\n invariant(\n !old || old === which,\n `Cannot change root %s __typename more than once`,\n which\n );\n // First, delete any old __typename associated with this rootId from\n // rootIdsByTypename.\n if (old) delete this.rootIdsByTypename[old];\n // Now make this the only __typename that maps to this rootId.\n this.rootIdsByTypename[typename] = rootId;\n // Finally, update the __typename associated with this rootId.\n this.rootTypenamesById[rootId] = typename;\n }\n }\n\n public addPossibleTypes(possibleTypes: PossibleTypesMap) {\n (this.usingPossibleTypes as boolean) = true;\n Object.keys(possibleTypes).forEach((supertype) => {\n // Make sure all types have an entry in this.supertypeMap, even if\n // their supertype set is empty, so we can return false immediately\n // from policies.fragmentMatches for unknown supertypes.\n this.getSupertypeSet(supertype, true);\n\n possibleTypes[supertype].forEach((subtype) => {\n this.getSupertypeSet(subtype, true)!.add(supertype);\n const match = subtype.match(TypeOrFieldNameRegExp);\n if (!match || match[0] !== subtype) {\n // TODO Don't interpret just any invalid typename as a RegExp.\n this.fuzzySubtypes.set(subtype, new RegExp(subtype));\n }\n });\n });\n }\n\n private getTypePolicy(typename: string): Policies[\"typePolicies\"][string] {\n if (!hasOwn.call(this.typePolicies, typename)) {\n const policy: Policies[\"typePolicies\"][string] = (this.typePolicies[\n typename\n ] = Object.create(null));\n policy.fields = Object.create(null);\n\n // When the TypePolicy for typename is first accessed, instead of\n // starting with an empty policy object, inherit any properties or\n // fields from the type policies of the supertypes of typename.\n //\n // Any properties or fields defined explicitly within the TypePolicy\n // for typename will take precedence, and if there are multiple\n // supertypes, the properties of policies whose types were added\n // later via addPossibleTypes will take precedence over those of\n // earlier supertypes. TODO Perhaps we should warn about these\n // conflicts in development, and recommend defining the property\n // explicitly in the subtype policy?\n //\n // Field policy inheritance is atomic/shallow: you can't inherit a\n // field policy and then override just its read function, since read\n // and merge functions often need to cooperate, so changing only one\n // of them would be a recipe for inconsistency.\n //\n // Once the TypePolicy for typename has been accessed, its properties can\n // still be updated directly using addTypePolicies, but future changes to\n // inherited supertype policies will not be reflected in this subtype\n // policy, because this code runs at most once per typename.\n let supertypes = this.supertypeMap.get(typename);\n if (!supertypes && this.fuzzySubtypes.size) {\n // To make the inheritance logic work for unknown typename strings that\n // may have fuzzy supertypes, we give this typename an empty supertype\n // set and then populate it with any fuzzy supertypes that match.\n supertypes = this.getSupertypeSet(typename, true)!;\n // This only works for typenames that are directly matched by a fuzzy\n // supertype. What if there is an intermediate chain of supertypes?\n // While possible, that situation can only be solved effectively by\n // specifying the intermediate relationships via possibleTypes, manually\n // and in a non-fuzzy way.\n this.fuzzySubtypes.forEach((regExp, fuzzy) => {\n if (regExp.test(typename)) {\n // The fuzzy parameter is just the original string version of regExp\n // (not a valid __typename string), but we can look up the\n // associated supertype(s) in this.supertypeMap.\n const fuzzySupertypes = this.supertypeMap.get(fuzzy);\n if (fuzzySupertypes) {\n fuzzySupertypes.forEach((supertype) =>\n supertypes!.add(supertype)\n );\n }\n }\n });\n }\n if (supertypes && supertypes.size) {\n supertypes.forEach((supertype) => {\n const { fields, ...rest } = this.getTypePolicy(supertype);\n Object.assign(policy, rest);\n Object.assign(policy.fields, fields);\n });\n }\n }\n\n const inbox = this.toBeAdded[typename];\n if (inbox && inbox.length) {\n // Merge the pending policies into this.typePolicies, in the order they\n // were originally passed to addTypePolicy.\n inbox.splice(0).forEach((policy) => {\n this.updateTypePolicy(typename, policy);\n });\n }\n\n return this.typePolicies[typename];\n }\n\n private getFieldPolicy(\n typename: string | undefined,\n fieldName: string,\n createIfMissing: boolean\n ):\n | {\n keyFn?: KeyArgsFunction;\n read?: FieldReadFunction<any>;\n merge?: FieldMergeFunction<any>;\n }\n | undefined {\n if (typename) {\n const fieldPolicies = this.getTypePolicy(typename).fields;\n return (\n fieldPolicies[fieldName] ||\n (createIfMissing && (fieldPolicies[fieldName] = Object.create(null)))\n );\n }\n }\n\n private getSupertypeSet(\n subtype: string,\n createIfMissing: boolean\n ): Set<string> | undefined {\n let supertypeSet = this.supertypeMap.get(subtype);\n if (!supertypeSet && createIfMissing) {\n this.supertypeMap.set(subtype, (supertypeSet = new Set<string>()));\n }\n return supertypeSet;\n }\n\n public fragmentMatches(\n fragment: InlineFragmentNode | FragmentDefinitionNode,\n typename: string | undefined,\n result?: Record<string, any>,\n variables?: Record<string, any>\n ): boolean {\n if (!fragment.typeCondition) return true;\n\n // If the fragment has a type condition but the object we're matching\n // against does not have a __typename, the fragment cannot match.\n if (!typename) return false;\n\n const supertype = fragment.typeCondition.name.value;\n // Common case: fragment type condition and __typename are the same.\n if (typename === supertype) return true;\n\n if (this.usingPossibleTypes && this.supertypeMap.has(supertype)) {\n const typenameSupertypeSet = this.getSupertypeSet(typename, true)!;\n const workQueue = [typenameSupertypeSet];\n const maybeEnqueue = (subtype: string) => {\n const supertypeSet = this.getSupertypeSet(subtype, false);\n if (\n supertypeSet &&\n supertypeSet.size &&\n workQueue.indexOf(supertypeSet) < 0\n ) {\n workQueue.push(supertypeSet);\n }\n };\n\n // We need to check fuzzy subtypes only if we encountered fuzzy\n // subtype strings in addPossibleTypes, and only while writing to\n // the cache, since that's when selectionSetMatchesResult gives a\n // strong signal of fragment matching. The StoreReader class calls\n // policies.fragmentMatches without passing a result object, so\n // needToCheckFuzzySubtypes is always false while reading.\n let needToCheckFuzzySubtypes = !!(result && this.fuzzySubtypes.size);\n let checkingFuzzySubtypes = false;\n\n // It's important to keep evaluating workQueue.length each time through\n // the loop, because the queue can grow while we're iterating over it.\n for (let i = 0; i < workQueue.length; ++i) {\n const supertypeSet = workQueue[i];\n\n if (supertypeSet.has(supertype)) {\n if (!typenameSupertypeSet.has(supertype)) {\n if (checkingFuzzySubtypes) {\n invariant.warn(\n `Inferring subtype %s of supertype %s`,\n typename,\n supertype\n );\n }\n // Record positive results for faster future lookup.\n // Unfortunately, we cannot safely cache negative results,\n // because new possibleTypes data could always be added to the\n // Policies class.\n typenameSupertypeSet.add(supertype);\n }\n return true;\n }\n\n supertypeSet.forEach(maybeEnqueue);\n\n if (\n needToCheckFuzzySubtypes &&\n // Start checking fuzzy subtypes only after exhausting all\n // non-fuzzy subtypes (after the final iteration of the loop).\n i === workQueue.length - 1 &&\n // We could wait to compare fragment.selectionSet to result\n // after we verify the supertype, but this check is often less\n // expensive than that search, and we will have to do the\n // comparison anyway whenever we find a potential match.\n selectionSetMatchesResult(fragment.selectionSet, result!, variables)\n ) {\n // We don't always need to check fuzzy subtypes (if no result\n // was provided, or !this.fuzzySubtypes.size), but, when we do,\n // we only want to check them once.\n needToCheckFuzzySubtypes = false;\n checkingFuzzySubtypes = true;\n\n // If we find any fuzzy subtypes that match typename, extend the\n // workQueue to search through the supertypes of those fuzzy\n // subtypes. Otherwise the for-loop will terminate and we'll\n // return false below.\n this.fuzzySubtypes.forEach((regExp, fuzzyString) => {\n const match = typename.match(regExp);\n if (match && match[0] === typename) {\n maybeEnqueue(fuzzyString);\n }\n });\n }\n }\n }\n\n return false;\n }\n\n public hasKeyArgs(typename: string | undefined, fieldName: string) {\n const policy = this.getFieldPolicy(typename, fieldName, false);\n return !!(policy && policy.keyFn);\n }\n\n public getStoreFieldName(fieldSpec: FieldSpecifier): string {\n const { typename, fieldName } = fieldSpec;\n const policy = this.getFieldPolicy(typename, fieldName, false);\n let storeFieldName: Exclude<ReturnType<KeyArgsFunction>, KeySpecifier>;\n\n let keyFn = policy && policy.keyFn;\n if (keyFn && typename) {\n const context: Parameters<KeyArgsFunction>[1] = {\n typename,\n fieldName,\n field: fieldSpec.field || null,\n variables: fieldSpec.variables,\n };\n const args = argsFromFieldSpecifier(fieldSpec);\n while (keyFn) {\n const specifierOrString = keyFn(args, context);\n if (isArray(specifierOrString)) {\n keyFn = keyArgsFnFromSpecifier(specifierOrString);\n } else {\n // If the custom keyFn returns a falsy value, fall back to\n // fieldName instead.\n storeFieldName = specifierOrString || fieldName;\n break;\n }\n }\n }\n\n if (storeFieldName === void 0) {\n storeFieldName =\n fieldSpec.field ?\n storeKeyNameFromField(fieldSpec.field, fieldSpec.variables)\n : getStoreKeyName(fieldName, argsFromFieldSpecifier(fieldSpec));\n }\n\n // Returning false from a keyArgs function is like configuring\n // keyArgs: false, but more dynamic.\n if (storeFieldName === false) {\n return fieldName;\n }\n\n // Make sure custom field names start with the actual field.name.value\n // of the field, so we can always figure out which properties of a\n // StoreObject correspond to which original field names.\n return fieldName === fieldNameFromStoreName(storeFieldName) ? storeFieldName\n : fieldName + \":\" + storeFieldName;\n }\n\n public readField<V = StoreValue>(\n options: ReadFieldOptions,\n context: ReadMergeModifyContext\n ): SafeReadonly<V> | undefined {\n const objectOrReference = options.from;\n if (!objectOrReference) return;\n\n const nameOrField = options.field || options.fieldName;\n if (!nameOrField) return;\n\n if (options.typename === void 0) {\n const typename = context.store.getFieldValue<string>(\n objectOrReference,\n \"__typename\"\n );\n if (typename) options.typename = typename;\n }\n\n const storeFieldName = this.getStoreFieldName(options);\n const fieldName = fieldNameFromStoreName(storeFieldName);\n const existing = context.store.getFieldValue<V>(\n objectOrReference,\n storeFieldName\n );\n const policy = this.getFieldPolicy(options.typename, fieldName, false);\n const read = policy && policy.read;\n\n if (read) {\n const readOptions = makeFieldFunctionOptions(\n this,\n objectOrReference,\n options,\n context,\n context.store.getStorage(\n isReference(objectOrReference) ?\n objectOrReference.__ref\n : objectOrReference,\n storeFieldName\n )\n );\n\n // Call read(existing, readOptions) with cacheSlot holding this.cache.\n return cacheSlot.withValue(this.cache, read, [\n existing,\n readOptions,\n ]) as SafeReadonly<V>;\n }\n\n return existing;\n }\n\n public getReadFunction(\n typename: string | undefined,\n fieldName: string\n ): FieldReadFunction | undefined {\n const policy = this.getFieldPolicy(typename, fieldName, false);\n return policy && policy.read;\n }\n\n public getMergeFunction(\n parentTypename: string | undefined,\n fieldName: string,\n childTypename: string | undefined\n ): FieldMergeFunction | undefined {\n let policy:\n | Policies[\"typePolicies\"][string]\n | Policies[\"typePolicies\"][string][\"fields\"][string]\n | undefined = this.getFieldPolicy(parentTypename, fieldName, false);\n let merge = policy && policy.merge;\n if (!merge && childTypename) {\n policy = this.getTypePolicy(childTypename);\n merge = policy && policy.merge;\n }\n return merge;\n }\n\n public runMergeFunction(\n existing: StoreValue,\n incoming: StoreValue,\n { field, typename, merge }: MergeInfo,\n context: WriteContext,\n storage?: StorageType\n ) {\n if (merge === mergeTrueFn) {\n // Instead of going to the trouble of creating a full\n // FieldFunctionOptions object and calling mergeTrueFn, we can\n // simply call mergeObjects, as mergeTrueFn would.\n return makeMergeObjectsFunction(context.store)(\n existing as StoreObject,\n incoming as StoreObject\n );\n }\n\n if (merge === mergeFalseFn) {\n // Likewise for mergeFalseFn, whose implementation is even simpler.\n return incoming;\n }\n\n // If cache.writeQuery or cache.writeFragment was called with\n // options.overwrite set to true, we still call merge functions, but\n // the existing data is always undefined, so the merge function will\n // not attempt to combine the incoming data with the existing data.\n if (context.overwrite) {\n existing = void 0;\n }\n\n return merge(\n existing,\n incoming,\n makeFieldFunctionOptions(\n this,\n // Unlike options.readField for read functions, we do not fall\n // back to the current object if no foreignObjOrRef is provided,\n // because it's not clear what the current object should be for\n // merge functions: the (possibly undefined) existing object, or\n // the incoming object? If you think your merge function needs\n // to read sibling fields in order to produce a new value for\n // the current field, you might want to rethink your strategy,\n // because that's a recipe for making merge behavior sensitive\n // to the order in which fields are written into the cache.\n // However, readField(name, ref) is useful for merge functions\n // that need to deduplicate child objects and references.\n void 0,\n {\n typename,\n fieldName: field.name.value,\n field,\n variables: context.variables,\n },\n context,\n storage || Object.create(null)\n )\n );\n }\n}\n\nfunction makeFieldFunctionOptions(\n policies: Policies,\n objectOrReference: StoreObject | Reference | undefined,\n fieldSpec: FieldSpecifier,\n context: ReadMergeModifyContext,\n storage: StorageType\n): FieldFunctionOptions {\n const storeFieldName = policies.getStoreFieldName(fieldSpec);\n const fieldName = fieldNameFromStoreName(storeFieldName);\n const variables = fieldSpec.variables || context.variables;\n const { toReference, canRead } = context.store;\n\n return {\n args: argsFromFieldSpecifier(fieldSpec),\n field: fieldSpec.field || null,\n fieldName,\n storeFieldName,\n variables,\n isReference,\n toReference,\n storage,\n cache: policies.cache,\n canRead,\n readField<T>() {\n return policies.readField<T>(\n normalizeReadFieldOptions(arguments, objectOrReference, variables),\n context\n );\n },\n mergeObjects: makeMergeObjectsFunction(context.store),\n };\n}\n\nexport function normalizeReadFieldOptions(\n readFieldArgs: IArguments,\n objectOrReference: StoreObject | Reference | undefined,\n variables?: ReadMergeModifyContext[\"variables\"]\n): ReadFieldOptions {\n const { 0: fieldNameOrOptions, 1: from, length: argc } = readFieldArgs;\n\n let options: ReadFieldOptions;\n\n if (typeof fieldNameOrOptions === \"string\") {\n options = {\n fieldName: fieldNameOrOptions,\n // Default to objectOrReference only when no second argument was\n // passed for the from parameter, not when undefined is explicitly\n // passed as the second argument.\n from: argc > 1 ? from : objectOrReference,\n };\n } else {\n options = { ...fieldNameOrOptions };\n // Default to objectOrReference only when fieldNameOrOptions.from is\n // actually omitted, rather than just undefined.\n if (!hasOwn.call(options, \"from\")) {\n options.from = objectOrReference;\n }\n }\n\n if (__DEV__ && options.from === void 0) {\n invariant.warn(\n `Undefined 'from' passed to readField with arguments %s`,\n stringifyForDisplay(Array.from(readFieldArgs))\n );\n }\n\n if (void 0 === options.variables) {\n options.variables = variables;\n }\n\n return options;\n}\n\nfunction makeMergeObjectsFunction(\n store: NormalizedCache\n): MergeObjectsFunction {\n return function mergeObjects(existing, incoming) {\n if (isArray(existing) || isArray(incoming)) {\n throw newInvariantError(\"Cannot automatically merge arrays\");\n }\n\n // These dynamic checks are necessary because the parameters of a\n // custom merge function can easily have the any type, so the type\n // system cannot always enforce the StoreObject | Reference parameter\n // types of options.mergeObjects.\n if (isNonNullObject(existing) && isNonNullObject(incoming)) {\n const eType = store.getFieldValue(existing, \"__typename\");\n const iType = store.getFieldValue(incoming, \"__typename\");\n const typesDiffer = eType && iType && eType !== iType;\n\n if (typesDiffer) {\n return incoming;\n }\n\n if (isReference(existing) && storeValueIsStoreObject(incoming)) {\n // Update the normalized EntityStore for the entity identified by\n // existing.__ref, preferring/overwriting any fields contributed by the\n // newer incoming StoreObject.\n store.merge(existing.__ref, incoming);\n return existing;\n }\n\n if (storeValueIsStoreObject(existing) && isReference(incoming)) {\n // Update the normalized EntityStore for the entity identified by\n // incoming.__ref, taking fields from the older existing object only if\n // those fields are not already present in the newer StoreObject\n // identified by incoming.__ref.\n store.merge(existing, incoming.__ref);\n return incoming;\n }\n\n if (\n storeValueIsStoreObject(existing) &&\n storeValueIsStoreObject(incoming)\n ) {\n return { ...existing, ...incoming };\n }\n }\n\n return incoming;\n };\n}\n"]}
@@ -1,4 +1,9 @@
1
+ var _a, _b;
1
2
  import gql from "graphql-tag";
3
+ import { TextEncoder, TextDecoder } from "util";
4
+ (_a = global.TextEncoder) !== null && _a !== void 0 ? _a : (global.TextEncoder = TextEncoder);
5
+ // @ts-ignore
6
+ (_b = global.TextDecoder) !== null && _b !== void 0 ? _b : (global.TextDecoder = TextDecoder);
2
7
  import "@testing-library/jest-dom";
3
8
  import { loadErrorMessageHandler } from "../../dev/loadErrorMessageHandler.js";
4
9
  import "../../testing/matchers/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/config/jest/setup.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,iCAAiC,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,gDAAgD;AAChD,GAAG,CAAC,uBAAuB,EAAE,CAAC;AAE9B,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,cAAO,CAAC,CAAC,CAAC;AAE3C,uBAAuB,EAAE,CAAC;AAE1B,SAAS,IAAI,CAAC,MAAqC;IAArC,uBAAA,EAAA,qCAAqC;IACjD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC;AAED,aAAa;AACb,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC;AAEvB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACpB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE;QACvC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC;KACzB,CAAC,CAAC;AACL,CAAC;AACD,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACzB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE;QAC5C,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;KAC9B,CAAC,CAAC;AACL,CAAC;AAED,aAAa;AACb,MAAM,CAAC,kBAAkB,CAAC,CAAC,oBAAoB,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAEzE,aAAa;AACb,UAAU,CAAC,0BAA0B,GAAG,EAAE,CAAC","sourcesContent":["import gql from \"graphql-tag\";\nimport \"@testing-library/jest-dom\";\nimport { loadErrorMessageHandler } from \"../../dev/loadErrorMessageHandler.js\";\nimport \"../../testing/matchers/index.js\";\nimport { areApolloErrorsEqual } from \"./areApolloErrorsEqual.js\";\nimport { areGraphQLErrorsEqual } from \"./areGraphQlErrorsEqual.js\";\n\n// Turn off warnings for repeated fragment names\ngql.disableFragmentWarnings();\n\nprocess.on(\"unhandledRejection\", () => {});\n\nloadErrorMessageHandler();\n\nfunction fail(reason = \"fail was called in a test.\") {\n expect(reason).toBe(undefined);\n}\n\n// @ts-ignore\nglobalThis.fail = fail;\n\nif (!Symbol.dispose) {\n Object.defineProperty(Symbol, \"dispose\", {\n value: Symbol(\"dispose\"),\n });\n}\nif (!Symbol.asyncDispose) {\n Object.defineProperty(Symbol, \"asyncDispose\", {\n value: Symbol(\"asyncDispose\"),\n });\n}\n\n// @ts-ignore\nexpect.addEqualityTesters([areApolloErrorsEqual, areGraphQLErrorsEqual]);\n\n// @ts-ignore\nglobalThis.REACT_FALLBACK_THROTTLE_MS = 10;\n"]}
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/config/jest/setup.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAChD,MAAA,MAAM,CAAC,WAAW,oCAAlB,MAAM,CAAC,WAAW,GAAK,WAAW,EAAC;AACnC,aAAa;AACb,MAAA,MAAM,CAAC,WAAW,oCAAlB,MAAM,CAAC,WAAW,GAAK,WAAW,EAAC;AACnC,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,iCAAiC,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,gDAAgD;AAChD,GAAG,CAAC,uBAAuB,EAAE,CAAC;AAE9B,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,cAAO,CAAC,CAAC,CAAC;AAE3C,uBAAuB,EAAE,CAAC;AAE1B,SAAS,IAAI,CAAC,MAAqC;IAArC,uBAAA,EAAA,qCAAqC;IACjD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC;AAED,aAAa;AACb,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC;AAEvB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACpB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE;QACvC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC;KACzB,CAAC,CAAC;AACL,CAAC;AACD,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACzB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE;QAC5C,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;KAC9B,CAAC,CAAC;AACL,CAAC;AAED,aAAa;AACb,MAAM,CAAC,kBAAkB,CAAC,CAAC,oBAAoB,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAEzE,aAAa;AACb,UAAU,CAAC,0BAA0B,GAAG,EAAE,CAAC","sourcesContent":["import gql from \"graphql-tag\";\nimport { TextEncoder, TextDecoder } from \"util\";\nglobal.TextEncoder ??= TextEncoder;\n// @ts-ignore\nglobal.TextDecoder ??= TextDecoder;\nimport \"@testing-library/jest-dom\";\nimport { loadErrorMessageHandler } from \"../../dev/loadErrorMessageHandler.js\";\nimport \"../../testing/matchers/index.js\";\nimport { areApolloErrorsEqual } from \"./areApolloErrorsEqual.js\";\nimport { areGraphQLErrorsEqual } from \"./areGraphQlErrorsEqual.js\";\n\n// Turn off warnings for repeated fragment names\ngql.disableFragmentWarnings();\n\nprocess.on(\"unhandledRejection\", () => {});\n\nloadErrorMessageHandler();\n\nfunction fail(reason = \"fail was called in a test.\") {\n expect(reason).toBe(undefined);\n}\n\n// @ts-ignore\nglobalThis.fail = fail;\n\nif (!Symbol.dispose) {\n Object.defineProperty(Symbol, \"dispose\", {\n value: Symbol(\"dispose\"),\n });\n}\nif (!Symbol.asyncDispose) {\n Object.defineProperty(Symbol, \"asyncDispose\", {\n value: Symbol(\"asyncDispose\"),\n });\n}\n\n// @ts-ignore\nexpect.addEqualityTesters([areApolloErrorsEqual, areGraphQLErrorsEqual]);\n\n// @ts-ignore\nglobalThis.REACT_FALLBACK_THROTTLE_MS = 10;\n"]}
@@ -48,16 +48,17 @@ var ApolloClient = /** @class */ (function () {
48
48
  */
49
49
  function ApolloClient(options) {
50
50
  var _this = this;
51
+ var _a;
51
52
  this.resetStoreCallbacks = [];
52
53
  this.clearStoreCallbacks = [];
53
54
  if (!options.cache) {
54
55
  throw newInvariantError(16);
55
56
  }
56
- var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, documentTransform = options.documentTransform, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b,
57
+ 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,
57
58
  // Expose the client instance as window.__APOLLO_CLIENT__ and call
58
59
  // onBroadcast in queryManager.broadcastQueries to enable browser
59
60
  // devtools, but disable them by default in production.
60
- connectToDevTools = options.connectToDevTools, _c = options.queryDeduplication, queryDeduplication = _c === void 0 ? true : _c, defaultOptions = options.defaultOptions, defaultContext = options.defaultContext, _d = options.assumeImmutableResults, assumeImmutableResults = _d === void 0 ? cache.assumeImmutableResults : _d, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version, devtools = options.devtools, dataMasking = options.dataMasking;
61
+ 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;
61
62
  var link = options.link;
62
63
  if (!link) {
63
64
  link =
@@ -69,7 +70,7 @@ var ApolloClient = /** @class */ (function () {
69
70
  this.queryDeduplication = queryDeduplication;
70
71
  this.defaultOptions = defaultOptions || Object.create(null);
71
72
  this.typeDefs = typeDefs;
72
- this.devtoolsConfig = __assign(__assign({}, devtools), { enabled: (devtools === null || devtools === void 0 ? void 0 : devtools.enabled) || connectToDevTools });
73
+ this.devtoolsConfig = __assign(__assign({}, devtools), { enabled: (_a = devtools === null || devtools === void 0 ? void 0 : devtools.enabled) !== null && _a !== void 0 ? _a : connectToDevTools });
73
74
  if (this.devtoolsConfig.enabled === undefined) {
74
75
  this.devtoolsConfig.enabled = globalThis.__DEV__ !== false;
75
76
  }
@@ -253,11 +254,14 @@ var ApolloClient = /** @class */ (function () {
253
254
  */
254
255
  ApolloClient.prototype.subscribe = function (options) {
255
256
  var _this = this;
257
+ var id = this.queryManager.generateQueryId();
256
258
  return this.queryManager
257
259
  .startGraphQLSubscription(options)
258
260
  .map(function (result) { return (__assign(__assign({}, result), { data: _this.queryManager.maskOperation({
259
261
  document: options.query,
260
262
  data: result.data,
263
+ fetchPolicy: options.fetchPolicy,
264
+ id: id,
261
265
  }) })); });
262
266
  };
263
267
  /**