@apollo/client 3.11.7 → 3.12.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/nasty-camels-pay.md +36 -0
- package/.changeset/pre.json +10 -0
- package/CHANGELOG.md +43 -0
- package/apollo-client.cjs +438 -111
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +218 -22
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +218 -22
- package/cache/core/cache.d.ts +13 -10
- package/cache/core/cache.js +32 -14
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +2 -1
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +4 -3
- package/cache/core/types/DataProxy.js.map +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/inMemoryCache.d.ts +3 -1
- package/cache/inmemory/inMemoryCache.js +7 -0
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +4 -4
- package/cache/inmemory/readFromStore.js +2 -2
- package/cache/inmemory/writeToStore.js +4 -4
- package/core/ApolloClient.d.ts +14 -6
- package/core/ApolloClient.js +14 -6
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +2 -2
- package/core/ObservableQuery.d.ts +17 -14
- package/core/ObservableQuery.js +29 -16
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +18 -3
- package/core/QueryManager.js +39 -14
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +285 -37
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +285 -37
- package/core/index.d.ts +1 -0
- package/core/index.js.map +1 -1
- package/core/masking.d.ts +4 -0
- package/core/masking.js +212 -0
- package/core/masking.js.map +1 -0
- package/core/types.d.ts +3 -2
- package/core/types.js.map +1 -1
- package/core/watchQueryOptions.d.ts +8 -6
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/dev.cjs +131 -87
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +131 -87
- package/invariantErrorCodes.js +140 -86
- package/link/core/ApolloLink.js +2 -2
- package/link/core/core.cjs +2 -2
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +2 -2
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/http.cjs +6 -6
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +6 -6
- package/link/http/selectHttpOptionsAndBody.js +3 -3
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/persisted-queries.cjs +2 -2
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
- package/link/utils/toPromise.js +1 -1
- package/link/utils/utils.cjs +2 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +2 -2
- package/link/utils/validateOperation.js +1 -1
- package/masking/index.d.ts +2 -0
- package/masking/index.js +2 -0
- package/masking/index.js.map +1 -0
- package/masking/internal/types.d.ts +15 -0
- package/masking/internal/types.js +2 -0
- package/masking/internal/types.js.map +1 -0
- package/masking/masking.cjs +3 -0
- package/masking/masking.cjs.map +1 -0
- package/masking/masking.cjs.native.js +3 -0
- package/masking/masking.d.cts +1 -0
- package/masking/package.json +8 -0
- package/masking/types.d.ts +44 -0
- package/masking/types.js +2 -0
- package/masking/types.js.map +1 -0
- package/package.json +2 -1
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs +3 -3
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +3 -3
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs +2 -2
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +2 -2
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs +24 -16
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +24 -16
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useFragment.d.ts +4 -3
- package/react/hooks/useFragment.js +12 -5
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +1 -1
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.js +2 -2
- package/react/hooks/useQuery.d.ts +4 -3
- package/react/hooks/useQuery.js +2 -1
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +2 -1
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +2 -1
- package/react/hooks/useSubscription.js +3 -3
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +6 -5
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/internal/cache/QueryReference.d.ts +5 -4
- package/react/internal/cache/QueryReference.js +1 -1
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/internal.cjs +2 -2
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +2 -2
- package/react/parser/index.js +5 -5
- package/react/parser/parser.cjs +5 -5
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +5 -5
- package/react/types/types.d.ts +18 -42
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs +3 -3
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +3 -3
- package/testing/core/mocking/mockLink.d.ts +3 -2
- package/testing/core/mocking/mockLink.js +3 -3
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/core/mocking/mockQueryManager.d.ts +1 -0
- package/testing/core/mocking/mockQueryManager.js +1 -1
- package/testing/core/mocking/mockQueryManager.js.map +1 -1
- package/testing/internal/disposables/index.d.ts +1 -0
- package/testing/internal/disposables/index.js +1 -0
- package/testing/internal/disposables/index.js.map +1 -1
- package/testing/internal/disposables/withProdMode.d.ts +4 -0
- package/testing/internal/disposables/withProdMode.js +10 -0
- package/testing/internal/disposables/withProdMode.js.map +1 -0
- package/testing/internal/scenarios/index.d.ts +28 -0
- package/testing/internal/scenarios/index.js +18 -2
- package/testing/internal/scenarios/index.js.map +1 -1
- package/utilities/common/maybeDeepFreeze.d.ts +1 -0
- package/utilities/common/maybeDeepFreeze.js +1 -1
- package/utilities/common/maybeDeepFreeze.js.map +1 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/graphql/directives.d.ts +3 -1
- package/utilities/graphql/directives.js +39 -5
- package/utilities/graphql/directives.js.map +1 -1
- package/utilities/graphql/fragments.js +3 -3
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/graphql/transform.d.ts +1 -0
- package/utilities/graphql/transform.js +15 -2
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +7 -3
- package/utilities/index.js +4 -3
- package/utilities/index.js.map +1 -1
- package/utilities/promises/preventUnhandledRejection.d.ts +2 -0
- package/utilities/promises/preventUnhandledRejection.js +5 -0
- package/utilities/promises/preventUnhandledRejection.js.map +1 -0
- package/utilities/subscriptions/relay/relay.cjs.map +1 -1
- package/utilities/subscriptions/urql/urql.cjs.map +1 -1
- package/utilities/types/NoInfer.d.ts +27 -0
- package/utilities/types/NoInfer.js +2 -0
- package/utilities/types/NoInfer.js.map +1 -0
- package/utilities/types/Prettify.d.ts +4 -0
- package/utilities/types/Prettify.js +2 -0
- package/utilities/types/Prettify.js.map +1 -0
- package/utilities/types/UnionToIntersection.d.ts +2 -0
- package/utilities/types/UnionToIntersection.js +2 -0
- package/utilities/types/UnionToIntersection.js.map +1 -0
- package/utilities/utilities.cjs +73 -19
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +73 -19
- package/version.js +1 -1
|
@@ -8,8 +8,8 @@ var optimism = require('optimism');
|
|
|
8
8
|
var utilities = require('../utilities');
|
|
9
9
|
var caches = require('@wry/caches');
|
|
10
10
|
var equal = require('@wry/equality');
|
|
11
|
-
var trie = require('@wry/trie');
|
|
12
11
|
var graphql = require('graphql');
|
|
12
|
+
var trie = require('@wry/trie');
|
|
13
13
|
|
|
14
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
15
15
|
|
|
@@ -126,6 +126,182 @@ function directiveIsNonreactive(dir) {
|
|
|
126
126
|
return dir.name.value === "nonreactive";
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
function maskFragment(data, document, cache, fragmentName) {
|
|
130
|
+
if (!cache.fragmentMatches) {
|
|
131
|
+
if (globalThis.__DEV__ !== false) {
|
|
132
|
+
warnOnImproperCacheImplementation();
|
|
133
|
+
}
|
|
134
|
+
return data;
|
|
135
|
+
}
|
|
136
|
+
var fragments = document.definitions.filter(function (node) {
|
|
137
|
+
return node.kind === graphql.Kind.FRAGMENT_DEFINITION;
|
|
138
|
+
});
|
|
139
|
+
if (typeof fragmentName === "undefined") {
|
|
140
|
+
globals.invariant(fragments.length === 1, 38, fragments.length);
|
|
141
|
+
fragmentName = fragments[0].name.value;
|
|
142
|
+
}
|
|
143
|
+
var fragment = fragments.find(function (fragment) { return fragment.name.value === fragmentName; });
|
|
144
|
+
globals.invariant(!!fragment, 39, fragmentName);
|
|
145
|
+
if (data == null) {
|
|
146
|
+
return data;
|
|
147
|
+
}
|
|
148
|
+
var context = {
|
|
149
|
+
operationType: "fragment",
|
|
150
|
+
operationName: fragment.name.value,
|
|
151
|
+
fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(document)),
|
|
152
|
+
cache: cache,
|
|
153
|
+
};
|
|
154
|
+
var _a = maskSelectionSet(data, fragment.selectionSet, context), masked = _a[0], changed = _a[1];
|
|
155
|
+
if (Object.isFrozen(data)) {
|
|
156
|
+
context.disableWarnings = true;
|
|
157
|
+
utilities.maybeDeepFreeze(masked);
|
|
158
|
+
context.disableWarnings = false;
|
|
159
|
+
}
|
|
160
|
+
return changed ? masked : data;
|
|
161
|
+
}
|
|
162
|
+
function maskSelectionSet(data, selectionSet, context, path) {
|
|
163
|
+
if (Array.isArray(data)) {
|
|
164
|
+
var changed_1 = false;
|
|
165
|
+
var masked = data.map(function (item, index) {
|
|
166
|
+
if (item === null) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
var _a = maskSelectionSet(item, selectionSet, context, globalThis.__DEV__ !== false ? "".concat(path || "", "[").concat(index, "]") : void 0), masked = _a[0], itemChanged = _a[1];
|
|
170
|
+
changed_1 || (changed_1 = itemChanged);
|
|
171
|
+
return itemChanged ? masked : item;
|
|
172
|
+
});
|
|
173
|
+
return [changed_1 ? masked : data, changed_1];
|
|
174
|
+
}
|
|
175
|
+
var result = selectionSet.selections.reduce(function (_a, selection) {
|
|
176
|
+
var memo = _a[0], changed = _a[1];
|
|
177
|
+
switch (selection.kind) {
|
|
178
|
+
case graphql.Kind.FIELD: {
|
|
179
|
+
var keyName = utilities.resultKeyNameFromField(selection);
|
|
180
|
+
var childSelectionSet = selection.selectionSet;
|
|
181
|
+
memo[keyName] = data[keyName];
|
|
182
|
+
if (childSelectionSet && data[keyName] !== null) {
|
|
183
|
+
var _b = maskSelectionSet(data[keyName], childSelectionSet, context, globalThis.__DEV__ !== false ? "".concat(path || "", ".").concat(keyName) : void 0), masked = _b[0], childChanged = _b[1];
|
|
184
|
+
if (childChanged ||
|
|
185
|
+
Object.keys(masked).length !== Object.keys(data[keyName]).length) {
|
|
186
|
+
memo[keyName] = masked;
|
|
187
|
+
changed = true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return [memo, changed];
|
|
191
|
+
}
|
|
192
|
+
case graphql.Kind.INLINE_FRAGMENT: {
|
|
193
|
+
if (selection.typeCondition &&
|
|
194
|
+
!context.cache.fragmentMatches(selection, data.__typename)) {
|
|
195
|
+
return [memo, changed];
|
|
196
|
+
}
|
|
197
|
+
var _c = maskSelectionSet(data, selection.selectionSet, context, path), fragmentData = _c[0], childChanged = _c[1];
|
|
198
|
+
return [
|
|
199
|
+
tslib.__assign(tslib.__assign({}, memo), fragmentData),
|
|
200
|
+
changed || childChanged,
|
|
201
|
+
];
|
|
202
|
+
}
|
|
203
|
+
case graphql.Kind.FRAGMENT_SPREAD: {
|
|
204
|
+
var fragmentName = selection.name.value;
|
|
205
|
+
var fragment = context.fragmentMap[fragmentName] ||
|
|
206
|
+
(context.fragmentMap[fragmentName] =
|
|
207
|
+
context.cache.lookupFragment(fragmentName));
|
|
208
|
+
globals.invariant(fragment, 40, fragmentName);
|
|
209
|
+
var mode = utilities.getFragmentMaskMode(selection);
|
|
210
|
+
if (mode === "mask") {
|
|
211
|
+
return [memo, true];
|
|
212
|
+
}
|
|
213
|
+
if (globalThis.__DEV__ !== false) {
|
|
214
|
+
if (mode === "migrate") {
|
|
215
|
+
return [
|
|
216
|
+
addFieldAccessorWarnings(memo, data, fragment.selectionSet, path || "", context),
|
|
217
|
+
true,
|
|
218
|
+
];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
var _d = maskSelectionSet(data, fragment.selectionSet, context, path), fragmentData = _d[0], changed_2 = _d[1];
|
|
222
|
+
return [tslib.__assign(tslib.__assign({}, memo), fragmentData), changed_2];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}, [Object.create(null), false]);
|
|
226
|
+
if ("__typename" in data && !("__typename" in result[0])) {
|
|
227
|
+
result[0].__typename = data.__typename;
|
|
228
|
+
}
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
function addFieldAccessorWarnings(memo, data, selectionSetNode, path, context) {
|
|
232
|
+
if (Array.isArray(data)) {
|
|
233
|
+
return data.map(function (item, index) {
|
|
234
|
+
return addFieldAccessorWarnings(memo[index] || Object.create(null), item, selectionSetNode, "".concat(path, "[").concat(index, "]"), context);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return selectionSetNode.selections.reduce(function (memo, selection) {
|
|
238
|
+
switch (selection.kind) {
|
|
239
|
+
case graphql.Kind.FIELD: {
|
|
240
|
+
var keyName = utilities.resultKeyNameFromField(selection);
|
|
241
|
+
var childSelectionSet = selection.selectionSet;
|
|
242
|
+
if (keyName in memo) {
|
|
243
|
+
return memo;
|
|
244
|
+
}
|
|
245
|
+
var value = data[keyName];
|
|
246
|
+
if (childSelectionSet) {
|
|
247
|
+
value = addFieldAccessorWarnings(memo[keyName] || Object.create(null), data[keyName], childSelectionSet, "".concat(path, ".").concat(keyName), context);
|
|
248
|
+
}
|
|
249
|
+
if (globalThis.__DEV__ !== false) {
|
|
250
|
+
addAccessorWarning(memo, value, keyName, path, context);
|
|
251
|
+
}
|
|
252
|
+
if (!(globalThis.__DEV__ !== false)) {
|
|
253
|
+
memo[keyName] = data[keyName];
|
|
254
|
+
}
|
|
255
|
+
return memo;
|
|
256
|
+
}
|
|
257
|
+
case graphql.Kind.INLINE_FRAGMENT: {
|
|
258
|
+
return addFieldAccessorWarnings(memo, data, selection.selectionSet, path, context);
|
|
259
|
+
}
|
|
260
|
+
case graphql.Kind.FRAGMENT_SPREAD: {
|
|
261
|
+
var fragment = context.fragmentMap[selection.name.value];
|
|
262
|
+
var mode = utilities.getFragmentMaskMode(selection);
|
|
263
|
+
if (mode === "mask") {
|
|
264
|
+
return memo;
|
|
265
|
+
}
|
|
266
|
+
if (mode === "unmask") {
|
|
267
|
+
var fragmentData = maskSelectionSet(data, fragment.selectionSet, context, path)[0];
|
|
268
|
+
return Object.assign(memo, fragmentData);
|
|
269
|
+
}
|
|
270
|
+
return addFieldAccessorWarnings(memo, data, fragment.selectionSet, path, context);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}, memo);
|
|
274
|
+
}
|
|
275
|
+
function addAccessorWarning(data, value, fieldName, path, context) {
|
|
276
|
+
var getValue = function () {
|
|
277
|
+
if (context.disableWarnings) {
|
|
278
|
+
return value;
|
|
279
|
+
}
|
|
280
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(41, context.operationName ?
|
|
281
|
+
"".concat(context.operationType, " '").concat(context.operationName, "'")
|
|
282
|
+
: "anonymous ".concat(context.operationType), "".concat(path, ".").concat(fieldName).replace(/^\./, ""));
|
|
283
|
+
getValue = function () { return value; };
|
|
284
|
+
return value;
|
|
285
|
+
};
|
|
286
|
+
Object.defineProperty(data, fieldName, {
|
|
287
|
+
get: function () {
|
|
288
|
+
return getValue();
|
|
289
|
+
},
|
|
290
|
+
set: function (value) {
|
|
291
|
+
getValue = function () { return value; };
|
|
292
|
+
},
|
|
293
|
+
enumerable: true,
|
|
294
|
+
configurable: true,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
var issuedWarning = false;
|
|
298
|
+
function warnOnImproperCacheImplementation() {
|
|
299
|
+
if (!issuedWarning) {
|
|
300
|
+
issuedWarning = true;
|
|
301
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(42);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
129
305
|
var ApolloCache = (function () {
|
|
130
306
|
function ApolloCache() {
|
|
131
307
|
this.assumeImmutableResults = false;
|
|
@@ -135,6 +311,9 @@ var ApolloCache = (function () {
|
|
|
135
311
|
cache: caches.WeakCache,
|
|
136
312
|
});
|
|
137
313
|
}
|
|
314
|
+
ApolloCache.prototype.lookupFragment = function (fragmentName) {
|
|
315
|
+
return null;
|
|
316
|
+
};
|
|
138
317
|
ApolloCache.prototype.batch = function (options) {
|
|
139
318
|
var _this = this;
|
|
140
319
|
var optimisticId = typeof options.optimistic === "string" ? options.optimistic
|
|
@@ -170,26 +349,36 @@ var ApolloCache = (function () {
|
|
|
170
349
|
var _this = this;
|
|
171
350
|
var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, otherOptions = tslib.__rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
|
|
172
351
|
var query = this.getFragmentDoc(fragment, fragmentName);
|
|
173
|
-
var
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
352
|
+
var id = typeof from === "undefined" || typeof from === "string" ?
|
|
353
|
+
from
|
|
354
|
+
: this.identify(from);
|
|
355
|
+
var dataMasking = !!options[Symbol.for("apollo.dataMasking")];
|
|
356
|
+
if (globalThis.__DEV__ !== false) {
|
|
357
|
+
var actualFragmentName = fragmentName || utilities.getFragmentDefinition(fragment).name.value;
|
|
358
|
+
if (!id) {
|
|
359
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(1, actualFragmentName);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
var diffOptions = tslib.__assign(tslib.__assign({}, otherOptions), { returnPartialData: true, id: id, query: query, optimistic: optimistic });
|
|
177
363
|
var latestDiff;
|
|
178
364
|
return new utilities.Observable(function (observer) {
|
|
179
365
|
return _this.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
|
|
366
|
+
var data = dataMasking ?
|
|
367
|
+
maskFragment(diff.result, fragment, _this, fragmentName)
|
|
368
|
+
: diff.result;
|
|
180
369
|
if (
|
|
181
370
|
latestDiff &&
|
|
182
|
-
equalByQuery(query, { data: latestDiff === null || latestDiff === void 0 ? void 0 : latestDiff.result }, { data:
|
|
371
|
+
equalByQuery(query, { data: latestDiff === null || latestDiff === void 0 ? void 0 : latestDiff.result }, { data: data })) {
|
|
183
372
|
return;
|
|
184
373
|
}
|
|
185
374
|
var result = {
|
|
186
|
-
data:
|
|
375
|
+
data: data,
|
|
187
376
|
complete: !!diff.complete,
|
|
188
377
|
};
|
|
189
378
|
if (diff.missing) {
|
|
190
379
|
result.missing = utilities.mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
|
|
191
380
|
}
|
|
192
|
-
latestDiff = diff;
|
|
381
|
+
latestDiff = tslib.__assign(tslib.__assign({}, diff), { result: data });
|
|
193
382
|
observer.next(result);
|
|
194
383
|
} }));
|
|
195
384
|
});
|
|
@@ -439,7 +628,7 @@ exports.EntityStore = (function () {
|
|
|
439
628
|
var incoming = typeof newer === "string" ? this.lookup((dataId = newer)) : newer;
|
|
440
629
|
if (!incoming)
|
|
441
630
|
return;
|
|
442
|
-
globals.invariant(typeof dataId === "string",
|
|
631
|
+
globals.invariant(typeof dataId === "string", 2);
|
|
443
632
|
var merged = new utilities.DeepMerger(storeObjectReconciler).merge(existing, incoming);
|
|
444
633
|
this.data[dataId] = merged;
|
|
445
634
|
if (merged !== existing) {
|
|
@@ -516,7 +705,7 @@ exports.EntityStore = (function () {
|
|
|
516
705
|
if (globalThis.__DEV__ !== false) {
|
|
517
706
|
var checkReference = function (ref) {
|
|
518
707
|
if (_this.lookup(ref.__ref) === undefined) {
|
|
519
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
708
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(3, ref);
|
|
520
709
|
return true;
|
|
521
710
|
}
|
|
522
711
|
};
|
|
@@ -542,7 +731,7 @@ exports.EntityStore = (function () {
|
|
|
542
731
|
}
|
|
543
732
|
}
|
|
544
733
|
if (seenReference && someNonReference !== undefined) {
|
|
545
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
734
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(4, someNonReference);
|
|
546
735
|
break;
|
|
547
736
|
}
|
|
548
737
|
}
|
|
@@ -1125,7 +1314,7 @@ var StoreReader = (function () {
|
|
|
1125
1314
|
else {
|
|
1126
1315
|
var fragment = utilities.getFragmentFromSelection(selection, context.lookupFragment);
|
|
1127
1316
|
if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
|
|
1128
|
-
throw globals.newInvariantError(
|
|
1317
|
+
throw globals.newInvariantError(10, selection.name.value);
|
|
1129
1318
|
}
|
|
1130
1319
|
if (fragment && policies.fragmentMatches(fragment, typename)) {
|
|
1131
1320
|
fragment.selectionSet.selections.forEach(workSet.add, workSet);
|
|
@@ -1208,7 +1397,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
1208
1397
|
if (utilities.isNonNullObject(value)) {
|
|
1209
1398
|
globals.invariant(
|
|
1210
1399
|
!utilities.isReference(value),
|
|
1211
|
-
|
|
1400
|
+
11,
|
|
1212
1401
|
getTypenameFromStoreObject(store, value),
|
|
1213
1402
|
field.name.value
|
|
1214
1403
|
);
|
|
@@ -1301,7 +1490,7 @@ function keyFieldsFnFromSpecifier(specifier) {
|
|
|
1301
1490
|
hasOwn.call(object, schemaKeyPath[0])) {
|
|
1302
1491
|
extracted = extractKeyPath(object, schemaKeyPath, extractKey);
|
|
1303
1492
|
}
|
|
1304
|
-
globals.invariant(extracted !== void 0,
|
|
1493
|
+
globals.invariant(extracted !== void 0, 5, schemaKeyPath.join("."), object);
|
|
1305
1494
|
return extracted;
|
|
1306
1495
|
}));
|
|
1307
1496
|
return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
|
|
@@ -1537,7 +1726,7 @@ var Policies = (function () {
|
|
|
1537
1726
|
var rootId = "ROOT_" + which.toUpperCase();
|
|
1538
1727
|
var old = this.rootTypenamesById[rootId];
|
|
1539
1728
|
if (typename !== old) {
|
|
1540
|
-
globals.invariant(!old || old === which,
|
|
1729
|
+
globals.invariant(!old || old === which, 6, which);
|
|
1541
1730
|
if (old)
|
|
1542
1731
|
delete this.rootIdsByTypename[old];
|
|
1543
1732
|
this.rootIdsByTypename[typename] = rootId;
|
|
@@ -1634,7 +1823,7 @@ var Policies = (function () {
|
|
|
1634
1823
|
if (supertypeSet.has(supertype)) {
|
|
1635
1824
|
if (!typenameSupertypeSet.has(supertype)) {
|
|
1636
1825
|
if (checkingFuzzySubtypes) {
|
|
1637
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
1826
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(7, typename, supertype);
|
|
1638
1827
|
}
|
|
1639
1828
|
typenameSupertypeSet.add(supertype);
|
|
1640
1829
|
}
|
|
@@ -1797,7 +1986,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
|
|
|
1797
1986
|
}
|
|
1798
1987
|
}
|
|
1799
1988
|
if (globalThis.__DEV__ !== false && options.from === void 0) {
|
|
1800
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
1989
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(8, utilities.stringifyForDisplay(Array.from(readFieldArgs)));
|
|
1801
1990
|
}
|
|
1802
1991
|
if (void 0 === options.variables) {
|
|
1803
1992
|
options.variables = variables;
|
|
@@ -1807,7 +1996,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
|
|
|
1807
1996
|
function makeMergeObjectsFunction(store) {
|
|
1808
1997
|
return function mergeObjects(existing, incoming) {
|
|
1809
1998
|
if (utilities.isArray(existing) || utilities.isArray(incoming)) {
|
|
1810
|
-
throw globals.newInvariantError(
|
|
1999
|
+
throw globals.newInvariantError(9);
|
|
1811
2000
|
}
|
|
1812
2001
|
if (utilities.isNonNullObject(existing) && utilities.isNonNullObject(incoming)) {
|
|
1813
2002
|
var eType = store.getFieldValue(existing, "__typename");
|
|
@@ -1867,7 +2056,7 @@ var StoreWriter = (function () {
|
|
|
1867
2056
|
context: context,
|
|
1868
2057
|
});
|
|
1869
2058
|
if (!utilities.isReference(ref)) {
|
|
1870
|
-
throw globals.newInvariantError(
|
|
2059
|
+
throw globals.newInvariantError(12, result);
|
|
1871
2060
|
}
|
|
1872
2061
|
context.incomingById.forEach(function (_a, dataId) {
|
|
1873
2062
|
var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
|
|
@@ -1975,7 +2164,7 @@ var StoreWriter = (function () {
|
|
|
1975
2164
|
!context.deferred &&
|
|
1976
2165
|
!utilities.addTypenameToDocument.added(field) &&
|
|
1977
2166
|
!policies.getReadFunction(typename, field.name.value)) {
|
|
1978
|
-
globalThis.__DEV__ !== false && globals.invariant.error(
|
|
2167
|
+
globalThis.__DEV__ !== false && globals.invariant.error(13, utilities.resultKeyNameFromField(field), result);
|
|
1979
2168
|
}
|
|
1980
2169
|
});
|
|
1981
2170
|
try {
|
|
@@ -2082,7 +2271,7 @@ var StoreWriter = (function () {
|
|
|
2082
2271
|
else {
|
|
2083
2272
|
var fragment = utilities.getFragmentFromSelection(selection, context.lookupFragment);
|
|
2084
2273
|
if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
|
|
2085
|
-
throw globals.newInvariantError(
|
|
2274
|
+
throw globals.newInvariantError(14, selection.name.value);
|
|
2086
2275
|
}
|
|
2087
2276
|
if (fragment &&
|
|
2088
2277
|
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
@@ -2222,7 +2411,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
2222
2411
|
}
|
|
2223
2412
|
});
|
|
2224
2413
|
}
|
|
2225
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
2414
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(15, fieldName, parentType, childTypenames.length ?
|
|
2226
2415
|
"either ensure all objects of type " +
|
|
2227
2416
|
childTypenames.join(" and ") +
|
|
2228
2417
|
" have an ID or a custom merge function, or "
|
|
@@ -2496,6 +2685,13 @@ var InMemoryCache = (function (_super) {
|
|
|
2496
2685
|
InMemoryCache.prototype.transformDocument = function (document) {
|
|
2497
2686
|
return this.addTypenameToDocument(this.addFragmentsToDocument(document));
|
|
2498
2687
|
};
|
|
2688
|
+
InMemoryCache.prototype.fragmentMatches = function (fragment, typename) {
|
|
2689
|
+
return this.policies.fragmentMatches(fragment, typename);
|
|
2690
|
+
};
|
|
2691
|
+
InMemoryCache.prototype.lookupFragment = function (fragmentName) {
|
|
2692
|
+
var _a;
|
|
2693
|
+
return ((_a = this.config.fragments) === null || _a === void 0 ? void 0 : _a.lookup(fragmentName)) || null;
|
|
2694
|
+
};
|
|
2499
2695
|
InMemoryCache.prototype.broadcastWatches = function (options) {
|
|
2500
2696
|
var _this = this;
|
|
2501
2697
|
if (!this.txCount) {
|
package/cache/core/cache.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { DocumentNode } from "graphql";
|
|
2
|
-
import type { StoreObject, Reference, DeepPartial } from "../../utilities/index.js";
|
|
1
|
+
import type { DocumentNode, FragmentDefinitionNode, InlineFragmentNode } from "graphql";
|
|
2
|
+
import type { StoreObject, Reference, DeepPartial, NoInfer } from "../../utilities/index.js";
|
|
3
3
|
import { Observable } from "../../utilities/index.js";
|
|
4
4
|
import type { DataProxy } from "./types/DataProxy.js";
|
|
5
5
|
import type { Cache } from "./types/Cache.js";
|
|
6
6
|
import { getApolloCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js";
|
|
7
7
|
import type { OperationVariables, TypedDocumentNode } from "../../core/types.js";
|
|
8
8
|
import type { MissingTree } from "./types/common.js";
|
|
9
|
+
import type { FragmentType, MaybeMasked, Unmasked } from "../../masking/index.js";
|
|
9
10
|
export type Transaction<T> = (c: ApolloCache<T>) => void;
|
|
10
11
|
/**
|
|
11
12
|
* Watched fragment options.
|
|
@@ -26,7 +27,7 @@ export interface WatchFragmentOptions<TData, TVars> {
|
|
|
26
27
|
*
|
|
27
28
|
* @docGroup 1. Required options
|
|
28
29
|
*/
|
|
29
|
-
from: StoreObject | Reference | string;
|
|
30
|
+
from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string;
|
|
30
31
|
/**
|
|
31
32
|
* Any variables that the GraphQL fragment may depend on.
|
|
32
33
|
*
|
|
@@ -55,17 +56,17 @@ export interface WatchFragmentOptions<TData, TVars> {
|
|
|
55
56
|
* Watched fragment results.
|
|
56
57
|
*/
|
|
57
58
|
export type WatchFragmentResult<TData> = {
|
|
58
|
-
data: TData
|
|
59
|
+
data: MaybeMasked<TData>;
|
|
59
60
|
complete: true;
|
|
60
61
|
missing?: never;
|
|
61
62
|
} | {
|
|
62
|
-
data: DeepPartial<TData
|
|
63
|
+
data: DeepPartial<MaybeMasked<TData>>;
|
|
63
64
|
complete: false;
|
|
64
65
|
missing: MissingTree;
|
|
65
66
|
};
|
|
66
67
|
export declare abstract class ApolloCache<TSerialized> implements DataProxy {
|
|
67
68
|
readonly assumeImmutableResults: boolean;
|
|
68
|
-
abstract read<TData = any, TVariables = any>(query: Cache.ReadOptions<TVariables, TData>): TData | null;
|
|
69
|
+
abstract read<TData = any, TVariables = any>(query: Cache.ReadOptions<TVariables, TData>): Unmasked<TData> | null;
|
|
69
70
|
abstract write<TData = any, TVariables = any>(write: Cache.WriteOptions<TData, TVariables>): Reference | undefined;
|
|
70
71
|
abstract diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>;
|
|
71
72
|
abstract watch<TData = any, TVariables = any>(watch: Cache.WatchOptions<TData, TVariables>): () => void;
|
|
@@ -84,6 +85,8 @@ export declare abstract class ApolloCache<TSerialized> implements DataProxy {
|
|
|
84
85
|
*/
|
|
85
86
|
abstract extract(optimistic?: boolean): TSerialized;
|
|
86
87
|
abstract removeOptimistic(id: string): void;
|
|
88
|
+
fragmentMatches?(fragment: InlineFragmentNode, typename: string): boolean;
|
|
89
|
+
lookupFragment(fragmentName: string): FragmentDefinitionNode | null;
|
|
87
90
|
batch<U>(options: Cache.BatchOptions<this, U>): U;
|
|
88
91
|
abstract performTransaction(transaction: Transaction<TSerialized>, optimisticId?: string | null): void;
|
|
89
92
|
recordOptimisticTransaction(transaction: Transaction<TSerialized>, optimisticId: string): void;
|
|
@@ -92,7 +95,7 @@ export declare abstract class ApolloCache<TSerialized> implements DataProxy {
|
|
|
92
95
|
identify(object: StoreObject | Reference): string | undefined;
|
|
93
96
|
gc(): string[];
|
|
94
97
|
modify<Entity extends Record<string, any> = Record<string, any>>(options: Cache.ModifyOptions<Entity>): boolean;
|
|
95
|
-
readQuery<QueryType, TVariables = any>(options: Cache.ReadQueryOptions<QueryType, TVariables>, optimistic?: boolean): QueryType | null;
|
|
98
|
+
readQuery<QueryType, TVariables = any>(options: Cache.ReadQueryOptions<QueryType, TVariables>, optimistic?: boolean): Unmasked<QueryType> | null;
|
|
96
99
|
/**
|
|
97
100
|
* Watches the cache store of the fragment according to the options specified and returns an `Observable`. We can subscribe to this `Observable` and receive updated results through an observer when the cache store changes.
|
|
98
101
|
*
|
|
@@ -106,11 +109,11 @@ export declare abstract class ApolloCache<TSerialized> implements DataProxy {
|
|
|
106
109
|
*/
|
|
107
110
|
watchFragment<TData = any, TVars = OperationVariables>(options: WatchFragmentOptions<TData, TVars>): Observable<WatchFragmentResult<TData>>;
|
|
108
111
|
private getFragmentDoc;
|
|
109
|
-
readFragment<FragmentType, TVariables = any>(options: Cache.ReadFragmentOptions<FragmentType, TVariables>, optimistic?: boolean): FragmentType | null;
|
|
112
|
+
readFragment<FragmentType, TVariables = any>(options: Cache.ReadFragmentOptions<FragmentType, TVariables>, optimistic?: boolean): Unmasked<FragmentType> | null;
|
|
110
113
|
writeQuery<TData = any, TVariables = any>({ id, data, ...options }: Cache.WriteQueryOptions<TData, TVariables>): Reference | undefined;
|
|
111
114
|
writeFragment<TData = any, TVariables = any>({ id, data, fragment, fragmentName, ...options }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined;
|
|
112
|
-
updateQuery<TData = any, TVariables = any>(options: Cache.UpdateQueryOptions<TData, TVariables>, update: (data: TData | null) => TData | null | void): TData | null;
|
|
113
|
-
updateFragment<TData = any, TVariables = any>(options: Cache.UpdateFragmentOptions<TData, TVariables>, update: (data: TData | null) => TData | null | void): TData | null;
|
|
115
|
+
updateQuery<TData = any, TVariables = any>(options: Cache.UpdateQueryOptions<TData, TVariables>, update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void): Unmasked<TData> | null;
|
|
116
|
+
updateFragment<TData = any, TVariables = any>(options: Cache.UpdateFragmentOptions<TData, TVariables>, update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void): Unmasked<TData> | null;
|
|
114
117
|
/**
|
|
115
118
|
* @experimental
|
|
116
119
|
* @internal
|
package/cache/core/cache.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { __assign, __rest } from "tslib";
|
|
2
2
|
import { wrap } from "optimism";
|
|
3
|
-
import { Observable, cacheSizes, getFragmentQueryDocument, mergeDeepArray, } from "../../utilities/index.js";
|
|
3
|
+
import { Observable, cacheSizes, getFragmentDefinition, getFragmentQueryDocument, mergeDeepArray, } from "../../utilities/index.js";
|
|
4
4
|
import { WeakCache } from "@wry/caches";
|
|
5
5
|
import { getApolloCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js";
|
|
6
6
|
import { equalByQuery } from "../../core/equalByQuery.js";
|
|
7
|
+
import { invariant } from "../../utilities/globals/index.js";
|
|
8
|
+
import { maskFragment } from "../../core/masking.js";
|
|
7
9
|
var ApolloCache = /** @class */ (function () {
|
|
8
10
|
function ApolloCache() {
|
|
9
11
|
this.assumeImmutableResults = false;
|
|
@@ -15,6 +17,12 @@ var ApolloCache = /** @class */ (function () {
|
|
|
15
17
|
cache: WeakCache,
|
|
16
18
|
});
|
|
17
19
|
}
|
|
20
|
+
// Function used to lookup a fragment when a fragment definition is not part
|
|
21
|
+
// of the GraphQL document. This is useful for caches, such as InMemoryCache,
|
|
22
|
+
// that register fragments ahead of time so they can be referenced by name.
|
|
23
|
+
ApolloCache.prototype.lookupFragment = function (fragmentName) {
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
18
26
|
// Transactional API
|
|
19
27
|
// The batch method is intended to replace/subsume both performTransaction
|
|
20
28
|
// and recordOptimisticTransaction, but performTransaction came first, so we
|
|
@@ -63,33 +71,43 @@ var ApolloCache = /** @class */ (function () {
|
|
|
63
71
|
var _this = this;
|
|
64
72
|
var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, otherOptions = __rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
|
|
65
73
|
var query = this.getFragmentDoc(fragment, fragmentName);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
// While our TypeScript types do not allow for `undefined` as a valid
|
|
75
|
+
// `from`, its possible `useFragment` gives us an `undefined` since it
|
|
76
|
+
// calls` cache.identify` and provides that value to `from`. We are
|
|
77
|
+
// adding this fix here however to ensure those using plain JavaScript
|
|
78
|
+
// and using `cache.identify` themselves will avoid seeing the obscure
|
|
79
|
+
// warning.
|
|
80
|
+
var id = typeof from === "undefined" || typeof from === "string" ?
|
|
81
|
+
from
|
|
82
|
+
: this.identify(from);
|
|
83
|
+
var dataMasking = !!options[Symbol.for("apollo.dataMasking")];
|
|
84
|
+
if (globalThis.__DEV__ !== false) {
|
|
85
|
+
var actualFragmentName = fragmentName || getFragmentDefinition(fragment).name.value;
|
|
86
|
+
if (!id) {
|
|
87
|
+
globalThis.__DEV__ !== false && invariant.warn(1, actualFragmentName);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
var diffOptions = __assign(__assign({}, otherOptions), { returnPartialData: true, id: id, query: query, optimistic: optimistic });
|
|
76
91
|
var latestDiff;
|
|
77
92
|
return new Observable(function (observer) {
|
|
78
93
|
return _this.watch(__assign(__assign({}, diffOptions), { immediate: true, callback: function (diff) {
|
|
94
|
+
var data = dataMasking ?
|
|
95
|
+
maskFragment(diff.result, fragment, _this, fragmentName)
|
|
96
|
+
: diff.result;
|
|
79
97
|
if (
|
|
80
98
|
// Always ensure we deliver the first result
|
|
81
99
|
latestDiff &&
|
|
82
|
-
equalByQuery(query, { data: latestDiff === null || latestDiff === void 0 ? void 0 : latestDiff.result }, { data:
|
|
100
|
+
equalByQuery(query, { data: latestDiff === null || latestDiff === void 0 ? void 0 : latestDiff.result }, { data: data })) {
|
|
83
101
|
return;
|
|
84
102
|
}
|
|
85
103
|
var result = {
|
|
86
|
-
data:
|
|
104
|
+
data: data,
|
|
87
105
|
complete: !!diff.complete,
|
|
88
106
|
};
|
|
89
107
|
if (diff.missing) {
|
|
90
108
|
result.missing = mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
|
|
91
109
|
}
|
|
92
|
-
latestDiff = diff;
|
|
110
|
+
latestDiff = __assign(__assign({}, diff), { result: data });
|
|
93
111
|
observer.next(result);
|
|
94
112
|
} }));
|
|
95
113
|
});
|
package/cache/core/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/cache/core/cache.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAOhC,OAAO,EACL,UAAU,EACV,UAAU,EAEV,wBAAwB,EACxB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,6BAA6B,EAAE,MAAM,+CAA+C,CAAC;AAM9F,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAgE1D;IAAA;QACkB,2BAAsB,GAAY,KAAK,CAAC;QAiMxD,oEAAoE;QACpE,qDAAqD;QAC7C,mBAAc,GAAG,IAAI,CAAC,wBAAwB,EAAE;YACtD,GAAG,EACD,UAAU,CAAC,8BAA8B,CAAC;4EACO;YACnD,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;IAiFL,CAAC;IA1OC,oBAAoB;IAEpB,0EAA0E;IAC1E,4EAA4E;IAC5E,4EAA4E;IAC5E,4EAA4E;IAC5E,4EAA4E;IACrE,2BAAK,GAAZ,UAAgB,OAAoC;QAApD,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QAEnD,OAAO,IAAI,CAAC,KAAK,CAAC;YAChB,MAAM,YAAC,KAAK;gBACV,IAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAoB,OAAO,CAAC,CAAC;gBAC1D,IAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC3B,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,IAAI;oBAAE,OAAO,KAAK,CAAC;gBACnD,KAAK,CAAC,UAAU,uBAAyB,OAAO,KAAE,IAAI,MAAA,IAAG,CAAC;gBAC1D,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAEM,oCAAc,GAArB,UACE,OAAuD,EACvD,MAAmD;QAEnD,OAAO,IAAI,CAAC,KAAK,CAAC;YAChB,MAAM,YAAC,KAAK;gBACV,IAAM,KAAK,GAAG,KAAK,CAAC,YAAY,CAAoB,OAAO,CAAC,CAAC;gBAC7D,IAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC3B,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,IAAI;oBAAE,OAAO,KAAK,CAAC;gBACnD,KAAK,CAAC,aAAa,uBAAyB,OAAO,KAAE,IAAI,MAAA,IAAG,CAAC;gBAC7D,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAUH,kBAAC;AAAD,CAAC,AA1RD,IA0RC;;AAED,IAAI,OAAO,EAAE,CAAC;IACZ,WAAW,CAAC,SAAS,CAAC,kBAAkB,GAAG,6BAA6B,CAAC;AAC3E,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\nimport { wrap } from \"optimism\";\n\nimport type {\n StoreObject,\n Reference,\n DeepPartial,\n} from \"../../utilities/index.js\";\nimport {\n Observable,\n cacheSizes,\n defaultCacheSizes,\n getFragmentQueryDocument,\n mergeDeepArray,\n} from \"../../utilities/index.js\";\nimport type { DataProxy } from \"./types/DataProxy.js\";\nimport type { Cache } from \"./types/Cache.js\";\nimport { WeakCache } from \"@wry/caches\";\nimport { getApolloCacheMemoryInternals } from \"../../utilities/caching/getMemoryInternals.js\";\nimport type {\n OperationVariables,\n TypedDocumentNode,\n} from \"../../core/types.js\";\nimport type { MissingTree } from \"./types/common.js\";\nimport { equalByQuery } from \"../../core/equalByQuery.js\";\n\nexport type Transaction<T> = (c: ApolloCache<T>) => void;\n\n/**\n * Watched fragment options.\n */\nexport interface WatchFragmentOptions<TData, TVars> {\n /**\n * A GraphQL fragment document parsed into an AST with the `gql`\n * template literal.\n *\n * @docGroup 1. Required options\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVars>;\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @docGroup 1. Required options\n */\n from: StoreObject | Reference | string;\n /**\n * Any variables that the GraphQL fragment may depend on.\n *\n * @docGroup 2. Cache options\n */\n variables?: TVars;\n /**\n * The name of the fragment defined in the fragment document.\n *\n * Required if the fragment document includes more than one fragment,\n * optional otherwise.\n *\n * @docGroup 2. Cache options\n */\n fragmentName?: string;\n /**\n * If `true`, `watchFragment` returns optimistic results.\n *\n * The default value is `true`.\n *\n * @docGroup 2. Cache options\n */\n optimistic?: boolean;\n}\n\n/**\n * Watched fragment results.\n */\nexport type WatchFragmentResult<TData> =\n | {\n data: TData;\n complete: true;\n missing?: never;\n }\n | {\n data: DeepPartial<TData>;\n complete: false;\n missing: MissingTree;\n };\n\nexport abstract class ApolloCache<TSerialized> implements DataProxy {\n public readonly assumeImmutableResults: boolean = false;\n\n // required to implement\n // core API\n public abstract read<TData = any, TVariables = any>(\n query: Cache.ReadOptions<TVariables, TData>\n ): TData | null;\n public abstract write<TData = any, TVariables = any>(\n write: Cache.WriteOptions<TData, TVariables>\n ): Reference | undefined;\n public abstract diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>;\n public abstract watch<TData = any, TVariables = any>(\n watch: Cache.WatchOptions<TData, TVariables>\n ): () => void;\n\n // Empty the cache and restart all current watches (unless\n // options.discardWatches is true).\n public abstract reset(options?: Cache.ResetOptions): Promise<void>;\n\n // Remove whole objects from the cache by passing just options.id, or\n // specific fields by passing options.field and/or options.args. If no\n // options.args are provided, all fields matching options.field (even\n // those with arguments) will be removed. Returns true iff any data was\n // removed from the cache.\n public abstract evict(options: Cache.EvictOptions): boolean;\n\n // initializer / offline / ssr API\n /**\n * Replaces existing state in the cache (if any) with the values expressed by\n * `serializedState`.\n *\n * Called when hydrating a cache (server side rendering, or offline storage),\n * and also (potentially) during hot reloads.\n */\n public abstract restore(\n serializedState: TSerialized\n ): ApolloCache<TSerialized>;\n\n /**\n * Exposes the cache's complete state, in a serializable format for later restoration.\n */\n public abstract extract(optimistic?: boolean): TSerialized;\n\n // Optimistic API\n\n public abstract removeOptimistic(id: string): void;\n\n // Transactional API\n\n // The batch method is intended to replace/subsume both performTransaction\n // and recordOptimisticTransaction, but performTransaction came first, so we\n // provide a default batch implementation that's just another way of calling\n // performTransaction. Subclasses of ApolloCache (such as InMemoryCache) can\n // override the batch method to do more interesting things with its options.\n public batch<U>(options: Cache.BatchOptions<this, U>): U {\n const optimisticId =\n typeof options.optimistic === \"string\" ? options.optimistic\n : options.optimistic === false ? null\n : void 0;\n let updateResult: U;\n this.performTransaction(\n () => (updateResult = options.update(this)),\n optimisticId\n );\n return updateResult!;\n }\n\n public abstract performTransaction(\n transaction: Transaction<TSerialized>,\n // Although subclasses may implement recordOptimisticTransaction\n // however they choose, the default implementation simply calls\n // performTransaction with a string as the second argument, allowing\n // performTransaction to handle both optimistic and non-optimistic\n // (broadcast-batching) transactions. Passing null for optimisticId is\n // also allowed, and indicates that performTransaction should apply\n // the transaction non-optimistically (ignoring optimistic data).\n optimisticId?: string | null\n ): void;\n\n public recordOptimisticTransaction(\n transaction: Transaction<TSerialized>,\n optimisticId: string\n ) {\n this.performTransaction(transaction, optimisticId);\n }\n\n // Optional API\n\n // Called once per input document, allowing the cache to make static changes\n // to the query, such as adding __typename fields.\n public transformDocument(document: DocumentNode): DocumentNode {\n return document;\n }\n\n // Called before each ApolloLink request, allowing the cache to make dynamic\n // changes to the query, such as filling in missing fragment definitions.\n public transformForLink(document: DocumentNode): DocumentNode {\n return document;\n }\n\n public identify(object: StoreObject | Reference): string | undefined {\n return;\n }\n\n public gc(): string[] {\n return [];\n }\n\n public modify<Entity extends Record<string, any> = Record<string, any>>(\n options: Cache.ModifyOptions<Entity>\n ): boolean {\n return false;\n }\n\n // DataProxy API\n public readQuery<QueryType, TVariables = any>(\n options: Cache.ReadQueryOptions<QueryType, TVariables>,\n optimistic = !!options.optimistic\n ): QueryType | null {\n return this.read({\n ...options,\n rootId: options.id || \"ROOT_QUERY\",\n optimistic,\n });\n }\n\n /** {@inheritDoc @apollo/client!ApolloClient#watchFragment:member(1)} */\n public watchFragment<TData = any, TVars = OperationVariables>(\n options: WatchFragmentOptions<TData, TVars>\n ): Observable<WatchFragmentResult<TData>> {\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...otherOptions\n } = options;\n const query = this.getFragmentDoc(fragment, fragmentName);\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...otherOptions,\n returnPartialData: true,\n id:\n // While our TypeScript types do not allow for `undefined` as a valid\n // `from`, its possible `useFragment` gives us an `undefined` since it\n // calls` cache.identify` and provides that value to `from`. We are\n // adding this fix here however to ensure those using plain JavaScript\n // and using `cache.identify` themselves will avoid seeing the obscure\n // warning.\n typeof from === \"undefined\" || typeof from === \"string\" ?\n from\n : this.identify(from),\n query,\n optimistic,\n };\n\n let latestDiff: DataProxy.DiffResult<TData> | undefined;\n\n return new Observable((observer) => {\n return this.watch<TData, TVars>({\n ...diffOptions,\n immediate: true,\n callback(diff) {\n if (\n // Always ensure we deliver the first result\n latestDiff &&\n equalByQuery(\n query,\n { data: latestDiff?.result },\n { data: diff.result }\n )\n ) {\n return;\n }\n\n const result = {\n data: diff.result as DeepPartial<TData>,\n complete: !!diff.complete,\n } as WatchFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(\n diff.missing.map((error) => error.missing)\n );\n }\n\n latestDiff = diff;\n observer.next(result);\n },\n });\n });\n }\n\n // Make sure we compute the same (===) fragment query document every\n // time we receive the same fragment in readFragment.\n private getFragmentDoc = wrap(getFragmentQueryDocument, {\n max:\n cacheSizes[\"cache.fragmentQueryDocuments\"] ||\n defaultCacheSizes[\"cache.fragmentQueryDocuments\"],\n cache: WeakCache,\n });\n\n public readFragment<FragmentType, TVariables = any>(\n options: Cache.ReadFragmentOptions<FragmentType, TVariables>,\n optimistic = !!options.optimistic\n ): FragmentType | null {\n return this.read({\n ...options,\n query: this.getFragmentDoc(options.fragment, options.fragmentName),\n rootId: options.id,\n optimistic,\n });\n }\n\n public writeQuery<TData = any, TVariables = any>({\n id,\n data,\n ...options\n }: Cache.WriteQueryOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n dataId: id || \"ROOT_QUERY\",\n result: data,\n })\n );\n }\n\n public writeFragment<TData = any, TVariables = any>({\n id,\n data,\n fragment,\n fragmentName,\n ...options\n }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n query: this.getFragmentDoc(fragment, fragmentName),\n dataId: id,\n result: data,\n })\n );\n }\n\n public updateQuery<TData = any, TVariables = any>(\n options: Cache.UpdateQueryOptions<TData, TVariables>,\n update: (data: TData | null) => TData | null | void\n ): TData | null {\n return this.batch({\n update(cache) {\n const value = cache.readQuery<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeQuery<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n public updateFragment<TData = any, TVariables = any>(\n options: Cache.UpdateFragmentOptions<TData, TVariables>,\n update: (data: TData | null) => TData | null | void\n ): TData | null {\n return this.batch({\n update(cache) {\n const value = cache.readFragment<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeFragment<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n /**\n * @experimental\n * @internal\n * This is not a stable API - it is used in development builds to expose\n * information to the DevTools.\n * Use at your own risk!\n */\n public getMemoryInternals?: typeof getApolloCacheMemoryInternals;\n}\n\nif (__DEV__) {\n ApolloCache.prototype.getMemoryInternals = getApolloCacheMemoryInternals;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/cache/core/cache.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAQhC,OAAO,EACL,UAAU,EACV,UAAU,EAEV,qBAAqB,EACrB,wBAAwB,EACxB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,6BAA6B,EAAE,MAAM,+CAA+C,CAAC;AAM9F,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAqErD;IAAA;QACkB,2BAAsB,GAAY,KAAK,CAAC;QAoOxD,oEAAoE;QACpE,qDAAqD;QAC7C,mBAAc,GAAG,IAAI,CAAC,wBAAwB,EAAE;YACtD,GAAG,EACD,UAAU,CAAC,8BAA8B,CAAC;4EACO;YACnD,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;IAiFL,CAAC;IAhQC,4EAA4E;IAC5E,6EAA6E;IAC7E,2EAA2E;IACpE,oCAAc,GAArB,UAAsB,YAAoB;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oBAAoB;IAEpB,0EAA0E;IAC1E,4EAA4E;IAC5E,4EAA4E;IAC5E,4EAA4E;IAC5E,4EAA4E;IACrE,2BAAK,GAAZ,UAAgB,OAAoC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IAAI,IAAI,KAAK,IAAI;oBAAE,OAAO,KAAK,CAAC;gBACnD,KAAK,CAAC,aAAa,uBAAyB,OAAO,KAAE,IAAI,MAAA,IAAG,CAAC;gBAC7D,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAUH,kBAAC;AAAD,CAAC,AA7TD,IA6TC;;AAED,IAAI,OAAO,EAAE,CAAC;IACZ,WAAW,CAAC,SAAS,CAAC,kBAAkB,GAAG,6BAA6B,CAAC;AAC3E,CAAC","sourcesContent":["import type {\n DocumentNode,\n FragmentDefinitionNode,\n InlineFragmentNode,\n} from \"graphql\";\nimport { wrap } from \"optimism\";\n\nimport type {\n StoreObject,\n Reference,\n DeepPartial,\n NoInfer,\n} from \"../../utilities/index.js\";\nimport {\n Observable,\n cacheSizes,\n defaultCacheSizes,\n getFragmentDefinition,\n getFragmentQueryDocument,\n mergeDeepArray,\n} from \"../../utilities/index.js\";\nimport type { DataProxy } from \"./types/DataProxy.js\";\nimport type { Cache } from \"./types/Cache.js\";\nimport { WeakCache } from \"@wry/caches\";\nimport { getApolloCacheMemoryInternals } from \"../../utilities/caching/getMemoryInternals.js\";\nimport type {\n OperationVariables,\n TypedDocumentNode,\n} from \"../../core/types.js\";\nimport type { MissingTree } from \"./types/common.js\";\nimport { equalByQuery } from \"../../core/equalByQuery.js\";\nimport { invariant } from \"../../utilities/globals/index.js\";\nimport { maskFragment } from \"../../core/masking.js\";\nimport type {\n FragmentType,\n MaybeMasked,\n Unmasked,\n} from \"../../masking/index.js\";\n\nexport type Transaction<T> = (c: ApolloCache<T>) => void;\n\n/**\n * Watched fragment options.\n */\nexport interface WatchFragmentOptions<TData, TVars> {\n /**\n * A GraphQL fragment document parsed into an AST with the `gql`\n * template literal.\n *\n * @docGroup 1. Required options\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVars>;\n /**\n * An object containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID\n * (uncommon).\n *\n * @docGroup 1. Required options\n */\n from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string;\n /**\n * Any variables that the GraphQL fragment may depend on.\n *\n * @docGroup 2. Cache options\n */\n variables?: TVars;\n /**\n * The name of the fragment defined in the fragment document.\n *\n * Required if the fragment document includes more than one fragment,\n * optional otherwise.\n *\n * @docGroup 2. Cache options\n */\n fragmentName?: string;\n /**\n * If `true`, `watchFragment` returns optimistic results.\n *\n * The default value is `true`.\n *\n * @docGroup 2. Cache options\n */\n optimistic?: boolean;\n}\n\n/**\n * Watched fragment results.\n */\nexport type WatchFragmentResult<TData> =\n | {\n data: MaybeMasked<TData>;\n complete: true;\n missing?: never;\n }\n | {\n data: DeepPartial<MaybeMasked<TData>>;\n complete: false;\n missing: MissingTree;\n };\n\nexport abstract class ApolloCache<TSerialized> implements DataProxy {\n public readonly assumeImmutableResults: boolean = false;\n\n // required to implement\n // core API\n public abstract read<TData = any, TVariables = any>(\n query: Cache.ReadOptions<TVariables, TData>\n ): Unmasked<TData> | null;\n public abstract write<TData = any, TVariables = any>(\n write: Cache.WriteOptions<TData, TVariables>\n ): Reference | undefined;\n public abstract diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>;\n public abstract watch<TData = any, TVariables = any>(\n watch: Cache.WatchOptions<TData, TVariables>\n ): () => void;\n\n // Empty the cache and restart all current watches (unless\n // options.discardWatches is true).\n public abstract reset(options?: Cache.ResetOptions): Promise<void>;\n\n // Remove whole objects from the cache by passing just options.id, or\n // specific fields by passing options.field and/or options.args. If no\n // options.args are provided, all fields matching options.field (even\n // those with arguments) will be removed. Returns true iff any data was\n // removed from the cache.\n public abstract evict(options: Cache.EvictOptions): boolean;\n\n // initializer / offline / ssr API\n /**\n * Replaces existing state in the cache (if any) with the values expressed by\n * `serializedState`.\n *\n * Called when hydrating a cache (server side rendering, or offline storage),\n * and also (potentially) during hot reloads.\n */\n public abstract restore(\n serializedState: TSerialized\n ): ApolloCache<TSerialized>;\n\n /**\n * Exposes the cache's complete state, in a serializable format for later restoration.\n */\n public abstract extract(optimistic?: boolean): TSerialized;\n\n // Optimistic API\n\n public abstract removeOptimistic(id: string): void;\n\n // Data masking API\n\n // Used by data masking to determine if an inline fragment with a type\n // condition matches a given typename.\n //\n // If not implemented by a cache subclass, data masking will effectively be\n // disabled since we will not be able to accurately determine if a given type\n // condition for a union or interface matches a particular type.\n public fragmentMatches?(\n fragment: InlineFragmentNode,\n typename: string\n ): boolean;\n\n // Function used to lookup a fragment when a fragment definition is not part\n // of the GraphQL document. This is useful for caches, such as InMemoryCache,\n // that register fragments ahead of time so they can be referenced by name.\n public lookupFragment(fragmentName: string): FragmentDefinitionNode | null {\n return null;\n }\n\n // Transactional API\n\n // The batch method is intended to replace/subsume both performTransaction\n // and recordOptimisticTransaction, but performTransaction came first, so we\n // provide a default batch implementation that's just another way of calling\n // performTransaction. Subclasses of ApolloCache (such as InMemoryCache) can\n // override the batch method to do more interesting things with its options.\n public batch<U>(options: Cache.BatchOptions<this, U>): U {\n const optimisticId =\n typeof options.optimistic === \"string\" ? options.optimistic\n : options.optimistic === false ? null\n : void 0;\n let updateResult: U;\n this.performTransaction(\n () => (updateResult = options.update(this)),\n optimisticId\n );\n return updateResult!;\n }\n\n public abstract performTransaction(\n transaction: Transaction<TSerialized>,\n // Although subclasses may implement recordOptimisticTransaction\n // however they choose, the default implementation simply calls\n // performTransaction with a string as the second argument, allowing\n // performTransaction to handle both optimistic and non-optimistic\n // (broadcast-batching) transactions. Passing null for optimisticId is\n // also allowed, and indicates that performTransaction should apply\n // the transaction non-optimistically (ignoring optimistic data).\n optimisticId?: string | null\n ): void;\n\n public recordOptimisticTransaction(\n transaction: Transaction<TSerialized>,\n optimisticId: string\n ) {\n this.performTransaction(transaction, optimisticId);\n }\n\n // Optional API\n\n // Called once per input document, allowing the cache to make static changes\n // to the query, such as adding __typename fields.\n public transformDocument(document: DocumentNode): DocumentNode {\n return document;\n }\n\n // Called before each ApolloLink request, allowing the cache to make dynamic\n // changes to the query, such as filling in missing fragment definitions.\n public transformForLink(document: DocumentNode): DocumentNode {\n return document;\n }\n\n public identify(object: StoreObject | Reference): string | undefined {\n return;\n }\n\n public gc(): string[] {\n return [];\n }\n\n public modify<Entity extends Record<string, any> = Record<string, any>>(\n options: Cache.ModifyOptions<Entity>\n ): boolean {\n return false;\n }\n\n // DataProxy API\n public readQuery<QueryType, TVariables = any>(\n options: Cache.ReadQueryOptions<QueryType, TVariables>,\n optimistic = !!options.optimistic\n ): Unmasked<QueryType> | null {\n return this.read({\n ...options,\n rootId: options.id || \"ROOT_QUERY\",\n optimistic,\n });\n }\n\n /** {@inheritDoc @apollo/client!ApolloClient#watchFragment:member(1)} */\n public watchFragment<TData = any, TVars = OperationVariables>(\n options: WatchFragmentOptions<TData, TVars>\n ): Observable<WatchFragmentResult<TData>> {\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...otherOptions\n } = options;\n const query = this.getFragmentDoc(fragment, fragmentName);\n // While our TypeScript types do not allow for `undefined` as a valid\n // `from`, its possible `useFragment` gives us an `undefined` since it\n // calls` cache.identify` and provides that value to `from`. We are\n // adding this fix here however to ensure those using plain JavaScript\n // and using `cache.identify` themselves will avoid seeing the obscure\n // warning.\n const id =\n typeof from === \"undefined\" || typeof from === \"string\" ?\n from\n : this.identify(from);\n const dataMasking = !!(options as any)[Symbol.for(\"apollo.dataMasking\")];\n\n if (__DEV__) {\n const actualFragmentName =\n fragmentName || getFragmentDefinition(fragment).name.value;\n\n if (!id) {\n invariant.warn(\n \"Could not identify object passed to `from` for '%s' fragment, either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object.\",\n actualFragmentName\n );\n }\n }\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...otherOptions,\n returnPartialData: true,\n id,\n query,\n optimistic,\n };\n\n let latestDiff: DataProxy.DiffResult<TData> | undefined;\n\n return new Observable((observer) => {\n return this.watch<TData, TVars>({\n ...diffOptions,\n immediate: true,\n callback: (diff) => {\n const data =\n dataMasking ?\n maskFragment(diff.result, fragment, this, fragmentName)\n : diff.result;\n\n if (\n // Always ensure we deliver the first result\n latestDiff &&\n equalByQuery(query, { data: latestDiff?.result }, { data })\n ) {\n return;\n }\n\n const result = {\n data,\n complete: !!diff.complete,\n } as WatchFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(\n diff.missing.map((error) => error.missing)\n );\n }\n\n latestDiff = { ...diff, result: data };\n observer.next(result);\n },\n });\n });\n }\n\n // Make sure we compute the same (===) fragment query document every\n // time we receive the same fragment in readFragment.\n private getFragmentDoc = wrap(getFragmentQueryDocument, {\n max:\n cacheSizes[\"cache.fragmentQueryDocuments\"] ||\n defaultCacheSizes[\"cache.fragmentQueryDocuments\"],\n cache: WeakCache,\n });\n\n public readFragment<FragmentType, TVariables = any>(\n options: Cache.ReadFragmentOptions<FragmentType, TVariables>,\n optimistic = !!options.optimistic\n ): Unmasked<FragmentType> | null {\n return this.read({\n ...options,\n query: this.getFragmentDoc(options.fragment, options.fragmentName),\n rootId: options.id,\n optimistic,\n });\n }\n\n public writeQuery<TData = any, TVariables = any>({\n id,\n data,\n ...options\n }: Cache.WriteQueryOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n dataId: id || \"ROOT_QUERY\",\n result: data,\n })\n );\n }\n\n public writeFragment<TData = any, TVariables = any>({\n id,\n data,\n fragment,\n fragmentName,\n ...options\n }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined {\n return this.write(\n Object.assign(options, {\n query: this.getFragmentDoc(fragment, fragmentName),\n dataId: id,\n result: data,\n })\n );\n }\n\n public updateQuery<TData = any, TVariables = any>(\n options: Cache.UpdateQueryOptions<TData, TVariables>,\n update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void\n ): Unmasked<TData> | null {\n return this.batch({\n update(cache) {\n const value = cache.readQuery<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeQuery<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n public updateFragment<TData = any, TVariables = any>(\n options: Cache.UpdateFragmentOptions<TData, TVariables>,\n update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void\n ): Unmasked<TData> | null {\n return this.batch({\n update(cache) {\n const value = cache.readFragment<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeFragment<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n /**\n * @experimental\n * @internal\n * This is not a stable API - it is used in development builds to expose\n * information to the DevTools.\n * Use at your own risk!\n */\n public getMemoryInternals?: typeof getApolloCacheMemoryInternals;\n}\n\nif (__DEV__) {\n ApolloCache.prototype.getMemoryInternals = getApolloCacheMemoryInternals;\n}\n"]}
|