@apollo/client 3.13.8 → 3.14.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/chilled-cameras-scream.md +5 -0
- package/.changeset/great-suns-cover.md +5 -0
- package/.changeset/perfect-donuts-roll.md +5 -0
- package/.changeset/popular-waves-drop.md +5 -0
- package/.changeset/pre.json +16 -0
- package/.changeset/shy-dragons-tease.md +5 -0
- package/.changeset/smooth-countries-cough.md +5 -0
- package/.changeset/spotty-walls-repair.md +5 -0
- package/CHANGELOG.md +20 -0
- package/README.md +80 -31
- package/apollo-client.cjs +354 -132
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +78 -21
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +78 -21
- package/cache/core/cache.js +27 -4
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +4 -4
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +2 -2
- package/cache/inmemory/inMemoryCache.js +15 -4
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/policies.js +18 -13
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +7 -0
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +14 -3
- package/cache/inmemory/types.js.map +1 -1
- package/core/ApolloClient.d.ts +191 -2
- package/core/ApolloClient.js +93 -7
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +2 -2
- package/core/ObservableQuery.js +10 -6
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.js +8 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +15 -12
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +93 -30
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +93 -30
- package/core/watchQueryOptions.d.ts +2 -2
- package/dev/dev.cjs +144 -84
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +144 -84
- package/invariantErrorCodes.js +158 -83
- package/link/core/ApolloLink.js +2 -2
- package/link/core/core.cjs +2 -2
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +2 -2
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/http.cjs +3 -3
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +3 -3
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/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/maskDefinition.js +2 -2
- package/masking/maskFragment.js +2 -2
- package/masking/maskOperation.js +1 -1
- package/masking/masking.cjs +6 -6
- package/masking/masking.cjs.map +1 -1
- package/masking/masking.cjs.native.js +6 -6
- package/masking/utils.js +1 -1
- package/package.json +1 -1
- package/react/components/Mutation.js +5 -0
- package/react/components/Mutation.js.map +1 -1
- package/react/components/Query.js +5 -0
- package/react/components/Query.js.map +1 -1
- package/react/components/Subscription.js +5 -0
- package/react/components/Subscription.js.map +1 -1
- package/react/components/components.cjs +34 -0
- package/react/components/components.cjs.map +1 -1
- package/react/components/components.cjs.native.js +34 -0
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloContext.js +7 -2
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs +9 -4
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +9 -4
- package/react/hoc/graphql.js +17 -4
- package/react/hoc/graphql.js.map +1 -1
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs +55 -9
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +55 -9
- package/react/hoc/mutation-hoc.js +8 -1
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/query-hoc.js +8 -1
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.js +8 -1
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs +264 -31
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +264 -31
- package/react/hooks/internal/index.d.ts +2 -0
- package/react/hooks/internal/index.js +2 -0
- package/react/hooks/internal/index.js.map +1 -1
- package/react/hooks/internal/useWarnRemoved.d.ts +2 -0
- package/react/hooks/internal/useWarnRemoved.js +14 -0
- package/react/hooks/internal/useWarnRemoved.js.map +1 -0
- package/react/hooks/internal/useWarnRemovedOption.d.ts +2 -0
- package/react/hooks/internal/useWarnRemovedOption.js +14 -0
- package/react/hooks/internal/useWarnRemovedOption.js.map +1 -0
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useBackgroundQuery.js +11 -3
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.js +30 -21
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +65 -0
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.js +12 -5
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.js +5 -1
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +2 -2
- package/react/hooks/useQuery.js +25 -7
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +3 -3
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +12 -6
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/internal/cache/QueryReference.d.ts +16 -0
- 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.d.ts +7 -0
- package/react/parser/index.js +17 -7
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +28 -7
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +28 -7
- package/react/query-preloader/createQueryPreloader.d.ts +2 -1
- package/react/query-preloader/createQueryPreloader.js +14 -5
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/react.cjs +40 -6
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +40 -6
- package/react/types/types.d.ts +303 -9
- package/react/types/types.documentation.d.ts +2 -3
- package/react/types/types.documentation.js.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs +2 -2
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +2 -2
- package/testing/core/mocking/mockLink.js +2 -2
- package/testing/react/MockedProvider.d.ts +27 -1
- package/testing/react/MockedProvider.js +16 -10
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +42 -11
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +42 -11
- package/utilities/deprecation/index.d.ts +11 -0
- package/utilities/deprecation/index.js +28 -0
- package/utilities/deprecation/index.js.map +1 -0
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/graphql/directives.js +7 -7
- package/utilities/graphql/fragments.js +3 -3
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/graphql/transform.js +2 -2
- package/utilities/utilities.cjs +22 -22
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +22 -22
- package/version.js +1 -1
package/react/parser/parser.cjs
CHANGED
|
@@ -4,13 +4,31 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var globals = require('../../utilities/globals');
|
|
6
6
|
var utilities = require('../../utilities');
|
|
7
|
-
require('tslib');
|
|
7
|
+
var tslib = require('tslib');
|
|
8
|
+
var optimism = require('optimism');
|
|
8
9
|
|
|
9
10
|
var globalCaches = {};
|
|
10
11
|
function registerGlobalCache(name, getSize) {
|
|
11
12
|
globalCaches[name] = getSize;
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
var slot = new optimism.Slot();
|
|
16
|
+
function isMuted(name) {
|
|
17
|
+
return (slot.getValue() || []).includes(name);
|
|
18
|
+
}
|
|
19
|
+
function muteDeprecations(name) {
|
|
20
|
+
var args = [];
|
|
21
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
22
|
+
args[_i - 1] = arguments[_i];
|
|
23
|
+
}
|
|
24
|
+
return slot.withValue.apply(slot, tslib.__spreadArray([Array.isArray(name) ? name : [name]], args, false));
|
|
25
|
+
}
|
|
26
|
+
function warnDeprecated(name, cb) {
|
|
27
|
+
if (!isMuted(name)) {
|
|
28
|
+
cb();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
14
32
|
exports.DocumentType = void 0;
|
|
15
33
|
(function (DocumentType) {
|
|
16
34
|
DocumentType[DocumentType["Query"] = 0] = "Query";
|
|
@@ -34,6 +52,9 @@ function operationName(type) {
|
|
|
34
52
|
return name;
|
|
35
53
|
}
|
|
36
54
|
function parser(document) {
|
|
55
|
+
warnDeprecated("parser", function () {
|
|
56
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(83);
|
|
57
|
+
});
|
|
37
58
|
if (!cache) {
|
|
38
59
|
cache = new utilities.AutoCleanedWeakCache(utilities.cacheSizes.parser || 1000 );
|
|
39
60
|
}
|
|
@@ -41,7 +62,7 @@ function parser(document) {
|
|
|
41
62
|
if (cached)
|
|
42
63
|
return cached;
|
|
43
64
|
var variables, type, name;
|
|
44
|
-
globals.invariant(!!document && !!document.kind,
|
|
65
|
+
globals.invariant(!!document && !!document.kind, 84, document);
|
|
45
66
|
var fragments = [];
|
|
46
67
|
var queries = [];
|
|
47
68
|
var mutations = [];
|
|
@@ -69,10 +90,10 @@ function parser(document) {
|
|
|
69
90
|
globals.invariant(!fragments.length ||
|
|
70
91
|
queries.length ||
|
|
71
92
|
mutations.length ||
|
|
72
|
-
subscriptions.length,
|
|
93
|
+
subscriptions.length, 85);
|
|
73
94
|
globals.invariant(
|
|
74
95
|
queries.length + mutations.length + subscriptions.length <= 1,
|
|
75
|
-
|
|
96
|
+
86,
|
|
76
97
|
document,
|
|
77
98
|
queries.length,
|
|
78
99
|
subscriptions.length,
|
|
@@ -84,7 +105,7 @@ function parser(document) {
|
|
|
84
105
|
var definitions = queries.length ? queries
|
|
85
106
|
: mutations.length ? mutations
|
|
86
107
|
: subscriptions;
|
|
87
|
-
globals.invariant(definitions.length === 1,
|
|
108
|
+
globals.invariant(definitions.length === 1, 87, document, definitions.length);
|
|
88
109
|
var definition = definitions[0];
|
|
89
110
|
variables = definition.variableDefinitions || [];
|
|
90
111
|
if (definition.name && definition.name.kind === "Name") {
|
|
@@ -104,12 +125,12 @@ if (globalThis.__DEV__ !== false) {
|
|
|
104
125
|
registerGlobalCache("parser", function () { return (cache ? cache.size : 0); });
|
|
105
126
|
}
|
|
106
127
|
function verifyDocumentType(document, type) {
|
|
107
|
-
var operation = parser
|
|
128
|
+
var operation = muteDeprecations("parser", parser, [document]);
|
|
108
129
|
var requiredOperationName = operationName(type);
|
|
109
130
|
var usedOperationName = operationName(operation.type);
|
|
110
131
|
globals.invariant(
|
|
111
132
|
operation.type === type,
|
|
112
|
-
|
|
133
|
+
88,
|
|
113
134
|
requiredOperationName,
|
|
114
135
|
requiredOperationName,
|
|
115
136
|
usedOperationName
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.cjs","sources":["../../utilities/caching/getMemoryInternals.js","index.js"],"sourcesContent":["import { __assign, __spreadArray } from \"tslib\";\nimport { cacheSizes } from \"./sizes.js\";\nvar globalCaches = {};\nexport function registerGlobalCache(name, getSize) {\n globalCaches[name] = getSize;\n}\n/**\n * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead\n * @internal\n */\nexport var getApolloClientMemoryInternals = globalThis.__DEV__ !== false ?\n _getApolloClientMemoryInternals\n : undefined;\n/**\n * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead\n * @internal\n */\nexport var getInMemoryCacheMemoryInternals = globalThis.__DEV__ !== false ?\n _getInMemoryCacheMemoryInternals\n : undefined;\n/**\n * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead\n * @internal\n */\nexport var getApolloCacheMemoryInternals = globalThis.__DEV__ !== false ?\n _getApolloCacheMemoryInternals\n : undefined;\nfunction getCurrentCacheSizes() {\n // `defaultCacheSizes` is a `const enum` that will be inlined during build, so we have to reconstruct it's shape here\n var defaults = {\n parser: 1000 /* defaultCacheSizes[\"parser\"] */,\n canonicalStringify: 1000 /* defaultCacheSizes[\"canonicalStringify\"] */,\n print: 2000 /* defaultCacheSizes[\"print\"] */,\n \"documentTransform.cache\": 2000 /* defaultCacheSizes[\"documentTransform.cache\"] */,\n \"queryManager.getDocumentInfo\": 2000 /* defaultCacheSizes[\"queryManager.getDocumentInfo\"] */,\n \"PersistedQueryLink.persistedQueryHashes\": 2000 /* defaultCacheSizes[\"PersistedQueryLink.persistedQueryHashes\"] */,\n \"fragmentRegistry.transform\": 2000 /* defaultCacheSizes[\"fragmentRegistry.transform\"] */,\n \"fragmentRegistry.lookup\": 1000 /* defaultCacheSizes[\"fragmentRegistry.lookup\"] */,\n \"fragmentRegistry.findFragmentSpreads\": 4000 /* defaultCacheSizes[\"fragmentRegistry.findFragmentSpreads\"] */,\n \"cache.fragmentQueryDocuments\": 1000 /* defaultCacheSizes[\"cache.fragmentQueryDocuments\"] */,\n \"removeTypenameFromVariables.getVariableDefinitions\": 2000 /* defaultCacheSizes[\"removeTypenameFromVariables.getVariableDefinitions\"] */,\n \"inMemoryCache.maybeBroadcastWatch\": 5000 /* defaultCacheSizes[\"inMemoryCache.maybeBroadcastWatch\"] */,\n \"inMemoryCache.executeSelectionSet\": 50000 /* defaultCacheSizes[\"inMemoryCache.executeSelectionSet\"] */,\n \"inMemoryCache.executeSubSelectedArray\": 10000 /* defaultCacheSizes[\"inMemoryCache.executeSubSelectedArray\"] */,\n };\n return Object.fromEntries(Object.entries(defaults).map(function (_a) {\n var k = _a[0], v = _a[1];\n return [\n k,\n cacheSizes[k] || v,\n ];\n }));\n}\nfunction _getApolloClientMemoryInternals() {\n var _a, _b, _c, _d, _e;\n if (!(globalThis.__DEV__ !== false))\n throw new Error(\"only supported in development mode\");\n return {\n limits: getCurrentCacheSizes(),\n sizes: __assign({ print: (_a = globalCaches.print) === null || _a === void 0 ? void 0 : _a.call(globalCaches), parser: (_b = globalCaches.parser) === null || _b === void 0 ? void 0 : _b.call(globalCaches), canonicalStringify: (_c = globalCaches.canonicalStringify) === null || _c === void 0 ? void 0 : _c.call(globalCaches), links: linkInfo(this.link), queryManager: {\n getDocumentInfo: this[\"queryManager\"][\"transformCache\"].size,\n documentTransforms: transformInfo(this[\"queryManager\"].documentTransform),\n } }, (_e = (_d = this.cache).getMemoryInternals) === null || _e === void 0 ? void 0 : _e.call(_d)),\n };\n}\nfunction _getApolloCacheMemoryInternals() {\n return {\n cache: {\n fragmentQueryDocuments: getWrapperInformation(this[\"getFragmentDoc\"]),\n },\n };\n}\nfunction _getInMemoryCacheMemoryInternals() {\n var fragments = this.config.fragments;\n return __assign(__assign({}, _getApolloCacheMemoryInternals.apply(this)), { addTypenameDocumentTransform: transformInfo(this[\"addTypenameTransform\"]), inMemoryCache: {\n executeSelectionSet: getWrapperInformation(this[\"storeReader\"][\"executeSelectionSet\"]),\n executeSubSelectedArray: getWrapperInformation(this[\"storeReader\"][\"executeSubSelectedArray\"]),\n maybeBroadcastWatch: getWrapperInformation(this[\"maybeBroadcastWatch\"]),\n }, fragmentRegistry: {\n findFragmentSpreads: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.findFragmentSpreads),\n lookup: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.lookup),\n transform: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.transform),\n } });\n}\nfunction isWrapper(f) {\n return !!f && \"dirtyKey\" in f;\n}\nfunction getWrapperInformation(f) {\n return isWrapper(f) ? f.size : undefined;\n}\nfunction isDefined(value) {\n return value != null;\n}\nfunction transformInfo(transform) {\n return recurseTransformInfo(transform).map(function (cache) { return ({ cache: cache }); });\n}\nfunction recurseTransformInfo(transform) {\n return transform ?\n __spreadArray(__spreadArray([\n getWrapperInformation(transform === null || transform === void 0 ? void 0 : transform[\"performWork\"])\n ], recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform[\"left\"]), true), recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform[\"right\"]), true).filter(isDefined)\n : [];\n}\nfunction linkInfo(link) {\n var _a;\n return link ?\n __spreadArray(__spreadArray([\n (_a = link === null || link === void 0 ? void 0 : link.getMemoryInternals) === null || _a === void 0 ? void 0 : _a.call(link)\n ], linkInfo(link === null || link === void 0 ? void 0 : link.left), true), linkInfo(link === null || link === void 0 ? void 0 : link.right), true).filter(isDefined)\n : [];\n}\n//# sourceMappingURL=getMemoryInternals.js.map","import { invariant } from \"../../utilities/globals/index.js\";\nimport { AutoCleanedWeakCache, cacheSizes, } from \"../../utilities/index.js\";\nimport { registerGlobalCache } from \"../../utilities/caching/getMemoryInternals.js\";\nexport var DocumentType;\n(function (DocumentType) {\n DocumentType[DocumentType[\"Query\"] = 0] = \"Query\";\n DocumentType[DocumentType[\"Mutation\"] = 1] = \"Mutation\";\n DocumentType[DocumentType[\"Subscription\"] = 2] = \"Subscription\";\n})(DocumentType || (DocumentType = {}));\nvar cache;\nexport function operationName(type) {\n var name;\n switch (type) {\n case DocumentType.Query:\n name = \"Query\";\n break;\n case DocumentType.Mutation:\n name = \"Mutation\";\n break;\n case DocumentType.Subscription:\n name = \"Subscription\";\n break;\n }\n return name;\n}\n// This parser is mostly used to safety check incoming documents.\nexport function parser(document) {\n if (!cache) {\n cache = new AutoCleanedWeakCache(cacheSizes.parser || 1000 /* defaultCacheSizes.parser */);\n }\n var cached = cache.get(document);\n if (cached)\n return cached;\n var variables, type, name;\n invariant(!!document && !!document.kind, 70, document);\n var fragments = [];\n var queries = [];\n var mutations = [];\n var subscriptions = [];\n for (var _i = 0, _a = document.definitions; _i < _a.length; _i++) {\n var x = _a[_i];\n if (x.kind === \"FragmentDefinition\") {\n fragments.push(x);\n continue;\n }\n if (x.kind === \"OperationDefinition\") {\n switch (x.operation) {\n case \"query\":\n queries.push(x);\n break;\n case \"mutation\":\n mutations.push(x);\n break;\n case \"subscription\":\n subscriptions.push(x);\n break;\n }\n }\n }\n invariant(!fragments.length ||\n queries.length ||\n mutations.length ||\n subscriptions.length, 71);\n invariant(\n queries.length + mutations.length + subscriptions.length <= 1,\n 72,\n document,\n queries.length,\n subscriptions.length,\n mutations.length\n );\n type = queries.length ? DocumentType.Query : DocumentType.Mutation;\n if (!queries.length && !mutations.length)\n type = DocumentType.Subscription;\n var definitions = queries.length ? queries\n : mutations.length ? mutations\n : subscriptions;\n invariant(definitions.length === 1, 73, document, definitions.length);\n var definition = definitions[0];\n variables = definition.variableDefinitions || [];\n if (definition.name && definition.name.kind === \"Name\") {\n name = definition.name.value;\n }\n else {\n name = \"data\"; // fallback to using data if no name\n }\n var payload = { name: name, type: type, variables: variables };\n cache.set(document, payload);\n return payload;\n}\nparser.resetCache = function () {\n cache = undefined;\n};\nif (globalThis.__DEV__ !== false) {\n registerGlobalCache(\"parser\", function () { return (cache ? cache.size : 0); });\n}\nexport function verifyDocumentType(document, type) {\n var operation = parser(document);\n var requiredOperationName = operationName(type);\n var usedOperationName = operationName(operation.type);\n invariant(\n operation.type === type,\n 74,\n requiredOperationName,\n requiredOperationName,\n usedOperationName\n );\n}\n//# sourceMappingURL=index.js.map"],"names":["DocumentType","AutoCleanedWeakCache","cacheSizes","invariant"],"mappings":";;;;;;;;AAEA,IAAI,YAAY,GAAG,EAAE,CAAC;AACf,SAAS,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE;AACnD,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;AACjC;;ACFWA,8BAAa;AACxB,CAAC,UAAU,YAAY,EAAE;AACzB,IAAI,YAAY,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;AACtD,IAAI,YAAY,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC;AAC5D,IAAI,YAAY,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC;AACpE,CAAC,EAAEA,oBAAY,KAAKA,oBAAY,GAAG,EAAE,CAAC,CAAC,CAAC;AACxC,IAAI,KAAK,CAAC;AACH,SAAS,aAAa,CAAC,IAAI,EAAE;AACpC,IAAI,IAAI,IAAI,CAAC;AACb,IAAI,QAAQ,IAAI;AAChB,QAAQ,KAAKA,oBAAY,CAAC,KAAK;AAC/B,YAAY,IAAI,GAAG,OAAO,CAAC;AAC3B,YAAY,MAAM;AAClB,QAAQ,KAAKA,oBAAY,CAAC,QAAQ;AAClC,YAAY,IAAI,GAAG,UAAU,CAAC;AAC9B,YAAY,MAAM;AAClB,QAAQ,KAAKA,oBAAY,CAAC,YAAY;AACtC,YAAY,IAAI,GAAG,cAAc,CAAC;AAClC,YAAY,MAAM;AAClB,KAAK;AACL,IAAI,OAAO,IAAI,CAAC;AAChB,CAAC;AAEM,SAAS,MAAM,CAAC,QAAQ,EAAE;AACjC,IAAI,IAAI,CAAC,KAAK,EAAE;AAChB,QAAQ,KAAK,GA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;AAC5D,QAAQ,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;AACrC,KAAK;AACL,SAAS;AACT,QAAQ,IAAI,GAAG,MAAM,CAAC;AACtB,KAAK;AACL,IAAI,IAAI,OAAO,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AACnE,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACjC,IAAI,OAAO,OAAO,CAAC;AACnB,CAAC;AACD,MAAM,CAAC,UAAU,GAAG,YAAY;AAChC,IAAI,KAAK,GAAG,SAAS,CAAC;AACtB,CAAC,CAAC;AACF,IAAI,UAAU,CAAC,OAAO,KAAK,KAAK,EAAE;AAClC,IAAI,mBAAmB,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,KAAK,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;AACpF,CAAC;AACM,SAAS,kBAAkB,CAAC,QAAQ,EAAE,IAAI,EAAE;AACnD,IAAI,IAAI,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACrC,IAAI,IAAI,qBAAqB,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;AACpD,IAAI,IAAI,iBAAiB,GAAG,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC1D,IAAIA,iBAAS;AACb,QAAQ,SAAS,CAAC,IAAI,KAAK,IAAI;AAC/B,QAAQ,EAAE;AACV,QAAQ,qBAAqB;AAC7B,QAAQ,qBAAqB;AAC7B,QAAQ,iBAAiB;AACzB,KAAK,CAAC;AACN;;;;;;"}
|
|
1
|
+
{"version":3,"file":"parser.cjs","sources":["../../utilities/caching/getMemoryInternals.js","../../utilities/deprecation/index.js","index.js"],"sourcesContent":["import { __assign, __spreadArray } from \"tslib\";\nimport { cacheSizes } from \"./sizes.js\";\nvar globalCaches = {};\nexport function registerGlobalCache(name, getSize) {\n globalCaches[name] = getSize;\n}\n/**\n * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead\n * @internal\n */\nexport var getApolloClientMemoryInternals = globalThis.__DEV__ !== false ?\n _getApolloClientMemoryInternals\n : undefined;\n/**\n * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead\n * @internal\n */\nexport var getInMemoryCacheMemoryInternals = globalThis.__DEV__ !== false ?\n _getInMemoryCacheMemoryInternals\n : undefined;\n/**\n * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead\n * @internal\n */\nexport var getApolloCacheMemoryInternals = globalThis.__DEV__ !== false ?\n _getApolloCacheMemoryInternals\n : undefined;\nfunction getCurrentCacheSizes() {\n // `defaultCacheSizes` is a `const enum` that will be inlined during build, so we have to reconstruct it's shape here\n var defaults = {\n parser: 1000 /* defaultCacheSizes[\"parser\"] */,\n canonicalStringify: 1000 /* defaultCacheSizes[\"canonicalStringify\"] */,\n print: 2000 /* defaultCacheSizes[\"print\"] */,\n \"documentTransform.cache\": 2000 /* defaultCacheSizes[\"documentTransform.cache\"] */,\n \"queryManager.getDocumentInfo\": 2000 /* defaultCacheSizes[\"queryManager.getDocumentInfo\"] */,\n \"PersistedQueryLink.persistedQueryHashes\": 2000 /* defaultCacheSizes[\"PersistedQueryLink.persistedQueryHashes\"] */,\n \"fragmentRegistry.transform\": 2000 /* defaultCacheSizes[\"fragmentRegistry.transform\"] */,\n \"fragmentRegistry.lookup\": 1000 /* defaultCacheSizes[\"fragmentRegistry.lookup\"] */,\n \"fragmentRegistry.findFragmentSpreads\": 4000 /* defaultCacheSizes[\"fragmentRegistry.findFragmentSpreads\"] */,\n \"cache.fragmentQueryDocuments\": 1000 /* defaultCacheSizes[\"cache.fragmentQueryDocuments\"] */,\n \"removeTypenameFromVariables.getVariableDefinitions\": 2000 /* defaultCacheSizes[\"removeTypenameFromVariables.getVariableDefinitions\"] */,\n \"inMemoryCache.maybeBroadcastWatch\": 5000 /* defaultCacheSizes[\"inMemoryCache.maybeBroadcastWatch\"] */,\n \"inMemoryCache.executeSelectionSet\": 50000 /* defaultCacheSizes[\"inMemoryCache.executeSelectionSet\"] */,\n \"inMemoryCache.executeSubSelectedArray\": 10000 /* defaultCacheSizes[\"inMemoryCache.executeSubSelectedArray\"] */,\n };\n return Object.fromEntries(Object.entries(defaults).map(function (_a) {\n var k = _a[0], v = _a[1];\n return [\n k,\n cacheSizes[k] || v,\n ];\n }));\n}\nfunction _getApolloClientMemoryInternals() {\n var _a, _b, _c, _d, _e;\n if (!(globalThis.__DEV__ !== false))\n throw new Error(\"only supported in development mode\");\n return {\n limits: getCurrentCacheSizes(),\n sizes: __assign({ print: (_a = globalCaches.print) === null || _a === void 0 ? void 0 : _a.call(globalCaches), parser: (_b = globalCaches.parser) === null || _b === void 0 ? void 0 : _b.call(globalCaches), canonicalStringify: (_c = globalCaches.canonicalStringify) === null || _c === void 0 ? void 0 : _c.call(globalCaches), links: linkInfo(this.link), queryManager: {\n getDocumentInfo: this[\"queryManager\"][\"transformCache\"].size,\n documentTransforms: transformInfo(this[\"queryManager\"].documentTransform),\n } }, (_e = (_d = this.cache).getMemoryInternals) === null || _e === void 0 ? void 0 : _e.call(_d)),\n };\n}\nfunction _getApolloCacheMemoryInternals() {\n return {\n cache: {\n fragmentQueryDocuments: getWrapperInformation(this[\"getFragmentDoc\"]),\n },\n };\n}\nfunction _getInMemoryCacheMemoryInternals() {\n var fragments = this.config.fragments;\n return __assign(__assign({}, _getApolloCacheMemoryInternals.apply(this)), { addTypenameDocumentTransform: transformInfo(this[\"addTypenameTransform\"]), inMemoryCache: {\n executeSelectionSet: getWrapperInformation(this[\"storeReader\"][\"executeSelectionSet\"]),\n executeSubSelectedArray: getWrapperInformation(this[\"storeReader\"][\"executeSubSelectedArray\"]),\n maybeBroadcastWatch: getWrapperInformation(this[\"maybeBroadcastWatch\"]),\n }, fragmentRegistry: {\n findFragmentSpreads: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.findFragmentSpreads),\n lookup: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.lookup),\n transform: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.transform),\n } });\n}\nfunction isWrapper(f) {\n return !!f && \"dirtyKey\" in f;\n}\nfunction getWrapperInformation(f) {\n return isWrapper(f) ? f.size : undefined;\n}\nfunction isDefined(value) {\n return value != null;\n}\nfunction transformInfo(transform) {\n return recurseTransformInfo(transform).map(function (cache) { return ({ cache: cache }); });\n}\nfunction recurseTransformInfo(transform) {\n return transform ?\n __spreadArray(__spreadArray([\n getWrapperInformation(transform === null || transform === void 0 ? void 0 : transform[\"performWork\"])\n ], recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform[\"left\"]), true), recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform[\"right\"]), true).filter(isDefined)\n : [];\n}\nfunction linkInfo(link) {\n var _a;\n return link ?\n __spreadArray(__spreadArray([\n (_a = link === null || link === void 0 ? void 0 : link.getMemoryInternals) === null || _a === void 0 ? void 0 : _a.call(link)\n ], linkInfo(link === null || link === void 0 ? void 0 : link.left), true), linkInfo(link === null || link === void 0 ? void 0 : link.right), true).filter(isDefined)\n : [];\n}\n//# sourceMappingURL=getMemoryInternals.js.map","import { __spreadArray } from \"tslib\";\nimport { Slot } from \"optimism\";\nimport { invariant } from \"../globals/index.js\";\nvar slot = new Slot();\nfunction isMuted(name) {\n return (slot.getValue() || []).includes(name);\n}\nexport function muteDeprecations(name) {\n var args = [];\n for (var _i = 1; _i < arguments.length; _i++) {\n args[_i - 1] = arguments[_i];\n }\n return slot.withValue.apply(slot, __spreadArray([Array.isArray(name) ? name : [name]], args, false));\n}\nexport function warnRemovedOption(options, name, callSite, recommendation) {\n if (recommendation === void 0) { recommendation = \"Please remove this option.\"; }\n warnDeprecated(name, function () {\n if (name in options) {\n globalThis.__DEV__ !== false && invariant.warn(91, callSite, name, recommendation);\n }\n });\n}\nexport function warnDeprecated(name, cb) {\n if (!isMuted(name)) {\n cb();\n }\n}\n//# sourceMappingURL=index.js.map","import { invariant } from \"../../utilities/globals/index.js\";\nimport { AutoCleanedWeakCache, cacheSizes, } from \"../../utilities/index.js\";\nimport { registerGlobalCache } from \"../../utilities/caching/getMemoryInternals.js\";\nimport { muteDeprecations, warnDeprecated, } from \"../../utilities/deprecation/index.js\";\nexport var DocumentType;\n(function (DocumentType) {\n DocumentType[DocumentType[\"Query\"] = 0] = \"Query\";\n DocumentType[DocumentType[\"Mutation\"] = 1] = \"Mutation\";\n DocumentType[DocumentType[\"Subscription\"] = 2] = \"Subscription\";\n})(DocumentType || (DocumentType = {}));\nvar cache;\nexport function operationName(type) {\n var name;\n switch (type) {\n case DocumentType.Query:\n name = \"Query\";\n break;\n case DocumentType.Mutation:\n name = \"Mutation\";\n break;\n case DocumentType.Subscription:\n name = \"Subscription\";\n break;\n }\n return name;\n}\n/**\n * @deprecated `parser` will be removed in Apollo Client 4.0.\n *\n * **Recommended now**\n *\n * Remove all usages of `parser` as it is an internal implementation detail.\n */\nexport function parser(document) {\n warnDeprecated(\"parser\", function () {\n globalThis.__DEV__ !== false && invariant.warn(83);\n });\n if (!cache) {\n cache = new AutoCleanedWeakCache(cacheSizes.parser || 1000 /* defaultCacheSizes.parser */);\n }\n var cached = cache.get(document);\n if (cached)\n return cached;\n var variables, type, name;\n invariant(!!document && !!document.kind, 84, document);\n var fragments = [];\n var queries = [];\n var mutations = [];\n var subscriptions = [];\n for (var _i = 0, _a = document.definitions; _i < _a.length; _i++) {\n var x = _a[_i];\n if (x.kind === \"FragmentDefinition\") {\n fragments.push(x);\n continue;\n }\n if (x.kind === \"OperationDefinition\") {\n switch (x.operation) {\n case \"query\":\n queries.push(x);\n break;\n case \"mutation\":\n mutations.push(x);\n break;\n case \"subscription\":\n subscriptions.push(x);\n break;\n }\n }\n }\n invariant(!fragments.length ||\n queries.length ||\n mutations.length ||\n subscriptions.length, 85);\n invariant(\n queries.length + mutations.length + subscriptions.length <= 1,\n 86,\n document,\n queries.length,\n subscriptions.length,\n mutations.length\n );\n type = queries.length ? DocumentType.Query : DocumentType.Mutation;\n if (!queries.length && !mutations.length)\n type = DocumentType.Subscription;\n var definitions = queries.length ? queries\n : mutations.length ? mutations\n : subscriptions;\n invariant(definitions.length === 1, 87, document, definitions.length);\n var definition = definitions[0];\n variables = definition.variableDefinitions || [];\n if (definition.name && definition.name.kind === \"Name\") {\n name = definition.name.value;\n }\n else {\n name = \"data\"; // fallback to using data if no name\n }\n var payload = { name: name, type: type, variables: variables };\n cache.set(document, payload);\n return payload;\n}\nparser.resetCache = function () {\n cache = undefined;\n};\nif (globalThis.__DEV__ !== false) {\n registerGlobalCache(\"parser\", function () { return (cache ? cache.size : 0); });\n}\nexport function verifyDocumentType(document, type) {\n var operation = muteDeprecations(\"parser\", parser, [document]);\n var requiredOperationName = operationName(type);\n var usedOperationName = operationName(operation.type);\n invariant(\n operation.type === type,\n 88,\n requiredOperationName,\n requiredOperationName,\n usedOperationName\n );\n}\n//# sourceMappingURL=index.js.map"],"names":["Slot","__spreadArray","DocumentType","invariant","AutoCleanedWeakCache","cacheSizes"],"mappings":";;;;;;;;;AAEA,IAAI,YAAY,GAAG,EAAE,CAAC;AACf,SAAS,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE;AACnD,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;AACjC;;ACFA,IAAI,IAAI,GAAG,IAAIA,aAAI,EAAE,CAAC;AACtB,SAAS,OAAO,CAAC,IAAI,EAAE;AACvB,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC;AACM,SAAS,gBAAgB,CAAC,IAAI,EAAE;AACvC,IAAI,IAAI,IAAI,GAAG,EAAE,CAAC;AAClB,IAAI,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE;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AC1D,IAAIA,iBAAS;AACb,QAAQ,SAAS,CAAC,IAAI,KAAK,IAAI;AAC/B,QAAQ,EAAE;AACV,QAAQ,qBAAqB;AAC7B,QAAQ,qBAAqB;AAC7B,QAAQ,iBAAiB;AACzB,KAAK,CAAC;AACN;;;;;;"}
|
|
@@ -4,13 +4,31 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var globals = require('../../utilities/globals');
|
|
6
6
|
var utilities = require('../../utilities');
|
|
7
|
-
require('tslib');
|
|
7
|
+
var tslib = require('tslib');
|
|
8
|
+
var optimism = require('optimism');
|
|
8
9
|
|
|
9
10
|
var globalCaches = {};
|
|
10
11
|
function registerGlobalCache(name, getSize) {
|
|
11
12
|
globalCaches[name] = getSize;
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
var slot = new optimism.Slot();
|
|
16
|
+
function isMuted(name) {
|
|
17
|
+
return (slot.getValue() || []).includes(name);
|
|
18
|
+
}
|
|
19
|
+
function muteDeprecations(name) {
|
|
20
|
+
var args = [];
|
|
21
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
22
|
+
args[_i - 1] = arguments[_i];
|
|
23
|
+
}
|
|
24
|
+
return slot.withValue.apply(slot, tslib.__spreadArray([Array.isArray(name) ? name : [name]], args, false));
|
|
25
|
+
}
|
|
26
|
+
function warnDeprecated(name, cb) {
|
|
27
|
+
if (!isMuted(name)) {
|
|
28
|
+
cb();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
14
32
|
exports.DocumentType = void 0;
|
|
15
33
|
(function (DocumentType) {
|
|
16
34
|
DocumentType[DocumentType["Query"] = 0] = "Query";
|
|
@@ -34,6 +52,9 @@ function operationName(type) {
|
|
|
34
52
|
return name;
|
|
35
53
|
}
|
|
36
54
|
function parser(document) {
|
|
55
|
+
warnDeprecated("parser", function () {
|
|
56
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(83);
|
|
57
|
+
});
|
|
37
58
|
if (!cache) {
|
|
38
59
|
cache = new utilities.AutoCleanedWeakCache(utilities.cacheSizes.parser || 1000 );
|
|
39
60
|
}
|
|
@@ -41,7 +62,7 @@ function parser(document) {
|
|
|
41
62
|
if (cached)
|
|
42
63
|
return cached;
|
|
43
64
|
var variables, type, name;
|
|
44
|
-
globals.invariant(!!document && !!document.kind,
|
|
65
|
+
globals.invariant(!!document && !!document.kind, 84, document);
|
|
45
66
|
var fragments = [];
|
|
46
67
|
var queries = [];
|
|
47
68
|
var mutations = [];
|
|
@@ -69,10 +90,10 @@ function parser(document) {
|
|
|
69
90
|
globals.invariant(!fragments.length ||
|
|
70
91
|
queries.length ||
|
|
71
92
|
mutations.length ||
|
|
72
|
-
subscriptions.length,
|
|
93
|
+
subscriptions.length, 85);
|
|
73
94
|
globals.invariant(
|
|
74
95
|
queries.length + mutations.length + subscriptions.length <= 1,
|
|
75
|
-
|
|
96
|
+
86,
|
|
76
97
|
document,
|
|
77
98
|
queries.length,
|
|
78
99
|
subscriptions.length,
|
|
@@ -84,7 +105,7 @@ function parser(document) {
|
|
|
84
105
|
var definitions = queries.length ? queries
|
|
85
106
|
: mutations.length ? mutations
|
|
86
107
|
: subscriptions;
|
|
87
|
-
globals.invariant(definitions.length === 1,
|
|
108
|
+
globals.invariant(definitions.length === 1, 87, document, definitions.length);
|
|
88
109
|
var definition = definitions[0];
|
|
89
110
|
variables = definition.variableDefinitions || [];
|
|
90
111
|
if (definition.name && definition.name.kind === "Name") {
|
|
@@ -104,12 +125,12 @@ if (globalThis.__DEV__ !== false) {
|
|
|
104
125
|
registerGlobalCache("parser", function () { return (cache ? cache.size : 0); });
|
|
105
126
|
}
|
|
106
127
|
function verifyDocumentType(document, type) {
|
|
107
|
-
var operation = parser
|
|
128
|
+
var operation = muteDeprecations("parser", parser, [document]);
|
|
108
129
|
var requiredOperationName = operationName(type);
|
|
109
130
|
var usedOperationName = operationName(operation.type);
|
|
110
131
|
globals.invariant(
|
|
111
132
|
operation.type === type,
|
|
112
|
-
|
|
133
|
+
88,
|
|
113
134
|
requiredOperationName,
|
|
114
135
|
requiredOperationName,
|
|
115
136
|
usedOperationName
|
|
@@ -9,7 +9,7 @@ export type PreloadQueryOptions<TVariables extends OperationVariables = Operatio
|
|
|
9
9
|
*
|
|
10
10
|
* @deprecated
|
|
11
11
|
*
|
|
12
|
-
* Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option
|
|
12
|
+
* Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option. `canonizeResults` will be removed in Apollo Client 4.0.
|
|
13
13
|
*/
|
|
14
14
|
canonizeResults?: boolean;
|
|
15
15
|
/**
|
|
@@ -224,6 +224,7 @@ export interface PreloadQueryFunction {
|
|
|
224
224
|
* ```
|
|
225
225
|
*/
|
|
226
226
|
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: PreloadQueryOptionsArg<NoInfer<TVariables>>): PreloadedQueryRef<TData, TVariables>;
|
|
227
|
+
toPromise<TQueryRef extends PreloadedQueryRef<any, any>>(queryRef: TQueryRef): Promise<TQueryRef>;
|
|
227
228
|
}
|
|
228
229
|
/**
|
|
229
230
|
* A higher order function that returns a `preloadQuery` function which
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
2
|
import { InternalQueryReference, wrapQueryRef } from "../internal/index.js";
|
|
3
3
|
import { wrapHook } from "../hooks/internal/index.js";
|
|
4
|
+
import { muteDeprecations, warnRemovedOption, } from "../../utilities/deprecation/index.js";
|
|
4
5
|
/**
|
|
5
6
|
* A higher order function that returns a `preloadQuery` function which
|
|
6
7
|
* can be used to begin loading a query with the given `client`. This is useful
|
|
@@ -23,13 +24,21 @@ export function createQueryPreloader(client) {
|
|
|
23
24
|
return wrapHook("createQueryPreloader", _createQueryPreloader, client)(client);
|
|
24
25
|
}
|
|
25
26
|
var _createQueryPreloader = function (client) {
|
|
26
|
-
|
|
27
|
-
var _a, _b;
|
|
27
|
+
function preloadQuery(query, options) {
|
|
28
28
|
if (options === void 0) { options = Object.create(null); }
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
warnRemovedOption(options, "canonizeResults", "preloadQuery");
|
|
30
|
+
var queryRef = muteDeprecations("canonizeResults", function () {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
return new InternalQueryReference(client.watchQuery(__assign(__assign({}, options), { query: query })), {
|
|
33
|
+
autoDisposeTimeoutMs: (_b = (_a = client.defaultOptions.react) === null || _a === void 0 ? void 0 : _a.suspense) === null || _b === void 0 ? void 0 : _b.autoDisposeTimeoutMs,
|
|
34
|
+
});
|
|
31
35
|
});
|
|
32
36
|
return wrapQueryRef(queryRef);
|
|
33
|
-
}
|
|
37
|
+
}
|
|
38
|
+
return Object.assign(preloadQuery, {
|
|
39
|
+
toPromise: function (queryRef) {
|
|
40
|
+
return queryRef.toPromise();
|
|
41
|
+
},
|
|
42
|
+
});
|
|
34
43
|
};
|
|
35
44
|
//# sourceMappingURL=createQueryPreloader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createQueryPreloader.js","sourceRoot":"","sources":["../../../src/react/query-preloader/createQueryPreloader.ts"],"names":[],"mappings":";AAeA,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAG5E,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"createQueryPreloader.js","sourceRoot":"","sources":["../../../src/react/query-preloader/createQueryPreloader.ts"],"names":[],"mappings":";AAeA,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAG5E,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,sCAAsC,CAAC;AAwH9C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAyB;IAEzB,OAAO,QAAQ,CACb,sBAAsB,EACtB,qBAAqB,EACrB,MAAM,CACP,CAAC,MAAM,CAAC,CAAC;AACZ,CAAC;AAED,IAAM,qBAAqB,GAAgC,UAAC,MAAM;IAChE,SAAS,YAAY,CAInB,KAA0D,EAC1D,OACmD;QADnD,wBAAA,EAAA,UACgC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAEnD,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,EAAE,cAAc,CAAC,CAAC;QAE9D,IAAM,QAAQ,GAAG,gBAAgB,CAC/B,iBAAiB,EACjB;;YACE,OAAA,IAAI,sBAAsB,CACxB,MAAM,CAAC,UAAU,CAAC,sBACb,OAAO,KACV,KAAK,OAAA,GACyB,CAAC,EACjC;gBACE,oBAAoB,EAClB,MAAA,MAAA,MAAM,CAAC,cAAc,CAAC,KAAK,0CAAE,QAAQ,0CAAE,oBAAoB;aAC9D,CACF,CAAA;SAAA,CACJ,CAAC;QAEF,OAAO,YAAY,CAAC,QAAQ,CAAyC,CAAC;IACxE,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE;QACjC,SAAS,YACP,QAAmB;YAEnB,OAAO,QAAQ,CAAC,SAAS,EAAwB,CAAC;QACpD,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import type {\n ApolloClient,\n DefaultContext,\n DocumentNode,\n ErrorPolicy,\n OperationVariables,\n RefetchWritePolicy,\n TypedDocumentNode,\n WatchQueryFetchPolicy,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport type {\n DeepPartial,\n OnlyRequiredProperties,\n} from \"../../utilities/index.js\";\nimport { InternalQueryReference, wrapQueryRef } from \"../internal/index.js\";\nimport type { PreloadedQueryRef } from \"../internal/index.js\";\nimport type { NoInfer, VariablesOption } from \"../index.js\";\nimport { wrapHook } from \"../hooks/internal/index.js\";\nimport {\n muteDeprecations,\n warnRemovedOption,\n} from \"../../utilities/deprecation/index.js\";\n\nexport type PreloadQueryFetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n>;\n\nexport type PreloadQueryOptions<\n TVariables extends OperationVariables = OperationVariables,\n> = {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */\n canonizeResults?: boolean;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#context:member} */\n context?: DefaultContext;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: PreloadQueryFetchPolicy;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */\n returnPartialData?: boolean;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#refetchWritePolicy:member} */\n refetchWritePolicy?: RefetchWritePolicy;\n} & VariablesOption<TVariables>;\n\ntype PreloadQueryOptionsArg<\n TVariables extends OperationVariables,\n TOptions = unknown,\n> = [TVariables] extends [never] ?\n [options?: PreloadQueryOptions<never> & TOptions]\n: {} extends OnlyRequiredProperties<TVariables> ?\n [\n options?: PreloadQueryOptions<NoInfer<TVariables>> &\n Omit<TOptions, \"variables\">,\n ]\n: [\n options: PreloadQueryOptions<NoInfer<TVariables>> &\n Omit<TOptions, \"variables\">,\n ];\n\n/**\n * A function that will begin loading a query when called. It's result can be\n * read by `useReadQuery` which will suspend until the query is loaded.\n * This is useful when you want to start loading a query as early as possible\n * outside of a React component.\n *\n * @example\n * ```js\n * const preloadQuery = createQueryPreloader(client);\n * const queryRef = preloadQuery(query, { variables, ...otherOptions });\n *\n * function App() {\n * return (\n * <Suspense fallback={<div>Loading</div>}>\n * <MyQuery />\n * </Suspense>\n * );\n * }\n *\n * function MyQuery() {\n * const { data } = useReadQuery(queryRef);\n *\n * // do something with `data`\n * }\n * ```\n */\nexport interface PreloadQueryFunction {\n /** {@inheritDoc @apollo/client!PreloadQueryFunction:interface} */\n <\n TData,\n TVariables extends OperationVariables,\n TOptions extends Omit<PreloadQueryOptions, \"variables\">,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: PreloadQueryOptionsArg<NoInfer<TVariables>, TOptions>\n ): PreloadedQueryRef<\n TOptions[\"errorPolicy\"] extends \"ignore\" | \"all\" ?\n TOptions[\"returnPartialData\"] extends true ?\n DeepPartial<TData> | undefined\n : TData | undefined\n : TOptions[\"returnPartialData\"] extends true ? DeepPartial<TData>\n : TData,\n TVariables\n >;\n\n /** {@inheritDoc @apollo/client!PreloadQueryFunction:interface} */\n <TData = unknown, TVariables extends OperationVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: PreloadQueryOptions<NoInfer<TVariables>> & {\n returnPartialData: true;\n errorPolicy: \"ignore\" | \"all\";\n }\n ): PreloadedQueryRef<DeepPartial<TData> | undefined, TVariables>;\n\n /** {@inheritDoc @apollo/client!PreloadQueryFunction:interface} */\n <TData = unknown, TVariables extends OperationVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: PreloadQueryOptions<NoInfer<TVariables>> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n ): PreloadedQueryRef<TData | undefined, TVariables>;\n\n /** {@inheritDoc @apollo/client!PreloadQueryFunction:interface} */\n <TData = unknown, TVariables extends OperationVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: PreloadQueryOptions<NoInfer<TVariables>> & {\n returnPartialData: true;\n }\n ): PreloadedQueryRef<DeepPartial<TData>, TVariables>;\n\n /** {@inheritDoc @apollo/client!PreloadQueryFunction:interface} */\n <TData = unknown, TVariables extends OperationVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: PreloadQueryOptionsArg<NoInfer<TVariables>>\n ): PreloadedQueryRef<TData, TVariables>;\n\n toPromise<TQueryRef extends PreloadedQueryRef<any, any>>(\n queryRef: TQueryRef\n ): Promise<TQueryRef>;\n}\n\n/**\n * A higher order function that returns a `preloadQuery` function which\n * can be used to begin loading a query with the given `client`. This is useful\n * when you want to start loading a query as early as possible outside of a\n * React component.\n *\n * > Refer to the [Suspense - Initiating queries outside React](https://www.apollographql.com/docs/react/data/suspense#initiating-queries-outside-react) section for a more in-depth overview.\n *\n * @param client - The `ApolloClient` instance that will be used to load queries\n * from the returned `preloadQuery` function.\n * @returns The `preloadQuery` function.\n *\n * @example\n * ```js\n * const preloadQuery = createQueryPreloader(client);\n * ```\n * @since 3.9.0\n */\nexport function createQueryPreloader(\n client: ApolloClient<any>\n): PreloadQueryFunction {\n return wrapHook(\n \"createQueryPreloader\",\n _createQueryPreloader,\n client\n )(client);\n}\n\nconst _createQueryPreloader: typeof createQueryPreloader = (client) => {\n function preloadQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: PreloadQueryOptions<NoInfer<TVariables>> &\n VariablesOption<TVariables> = Object.create(null)\n ): PreloadedQueryRef<TData, TVariables> {\n warnRemovedOption(options, \"canonizeResults\", \"preloadQuery\");\n\n const queryRef = muteDeprecations(\n \"canonizeResults\",\n () =>\n new InternalQueryReference(\n client.watchQuery({\n ...options,\n query,\n } as WatchQueryOptions<any, any>),\n {\n autoDisposeTimeoutMs:\n client.defaultOptions.react?.suspense?.autoDisposeTimeoutMs,\n }\n )\n );\n\n return wrapQueryRef(queryRef) as PreloadedQueryRef<TData, TVariables>;\n }\n\n return Object.assign(preloadQuery, {\n toPromise<TQueryRef extends PreloadedQueryRef<any, any>>(\n queryRef: TQueryRef\n ): Promise<TQueryRef> {\n return queryRef.toPromise() as Promise<TQueryRef>;\n },\n });\n};\n"]}
|
package/react/react.cjs
CHANGED
|
@@ -2,12 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
require('../utilities/globals');
|
|
5
|
+
var globals = require('../utilities/globals');
|
|
6
6
|
var context = require('./context');
|
|
7
7
|
var hooks = require('./hooks');
|
|
8
8
|
var parser = require('./parser');
|
|
9
9
|
var tslib = require('tslib');
|
|
10
10
|
var internal = require('./internal');
|
|
11
|
+
var optimism = require('optimism');
|
|
12
|
+
|
|
13
|
+
var slot = new optimism.Slot();
|
|
14
|
+
function isMuted(name) {
|
|
15
|
+
return (slot.getValue() || []).includes(name);
|
|
16
|
+
}
|
|
17
|
+
function muteDeprecations(name) {
|
|
18
|
+
var args = [];
|
|
19
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
20
|
+
args[_i - 1] = arguments[_i];
|
|
21
|
+
}
|
|
22
|
+
return slot.withValue.apply(slot, tslib.__spreadArray([Array.isArray(name) ? name : [name]], args, false));
|
|
23
|
+
}
|
|
24
|
+
function warnRemovedOption(options, name, callSite, recommendation) {
|
|
25
|
+
if (recommendation === void 0) { recommendation = "Please remove this option."; }
|
|
26
|
+
warnDeprecated(name, function () {
|
|
27
|
+
if (name in options) {
|
|
28
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(91, callSite, name, recommendation);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function warnDeprecated(name, cb) {
|
|
33
|
+
if (!isMuted(name)) {
|
|
34
|
+
cb();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
11
37
|
|
|
12
38
|
var wrapperSymbol = Symbol.for("apollo.hook.wrappers");
|
|
13
39
|
function wrapHook(hookName, useHook, clientOrObsQuery) {
|
|
@@ -21,14 +47,22 @@ function createQueryPreloader(client) {
|
|
|
21
47
|
return wrapHook("createQueryPreloader", _createQueryPreloader, client)(client);
|
|
22
48
|
}
|
|
23
49
|
var _createQueryPreloader = function (client) {
|
|
24
|
-
|
|
25
|
-
var _a, _b;
|
|
50
|
+
function preloadQuery(query, options) {
|
|
26
51
|
if (options === void 0) { options = Object.create(null); }
|
|
27
|
-
|
|
28
|
-
|
|
52
|
+
warnRemovedOption(options, "canonizeResults", "preloadQuery");
|
|
53
|
+
var queryRef = muteDeprecations("canonizeResults", function () {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
return new internal.InternalQueryReference(client.watchQuery(tslib.__assign(tslib.__assign({}, options), { query: query })), {
|
|
56
|
+
autoDisposeTimeoutMs: (_b = (_a = client.defaultOptions.react) === null || _a === void 0 ? void 0 : _a.suspense) === null || _b === void 0 ? void 0 : _b.autoDisposeTimeoutMs,
|
|
57
|
+
});
|
|
29
58
|
});
|
|
30
59
|
return internal.wrapQueryRef(queryRef);
|
|
31
|
-
}
|
|
60
|
+
}
|
|
61
|
+
return Object.assign(preloadQuery, {
|
|
62
|
+
toPromise: function (queryRef) {
|
|
63
|
+
return queryRef.toPromise();
|
|
64
|
+
},
|
|
65
|
+
});
|
|
32
66
|
};
|
|
33
67
|
|
|
34
68
|
exports.ApolloConsumer = context.ApolloConsumer;
|
package/react/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.cjs","sources":["hooks/internal/wrapHook.js","query-preloader/createQueryPreloader.js"],"sourcesContent":["var wrapperSymbol = Symbol.for(\"apollo.hook.wrappers\");\n/**\n * @internal\n *\n * Makes an Apollo Client hook \"wrappable\".\n * That means that the Apollo Client instance can expose a \"wrapper\" that will be\n * used to wrap the original hook implementation with additional logic.\n * @example\n * ```tsx\n * // this is already done in `@apollo/client` for all wrappable hooks (see `WrappableHooks`)\n * // following this pattern\n * function useQuery() {\n * return wrapHook('useQuery', _useQuery, options.client)(query, options);\n * }\n * function _useQuery(query, options) {\n * // original implementation\n * }\n *\n * // this is what a library like `@apollo/client-react-streaming` would do\n * class ApolloClientWithStreaming extends ApolloClient {\n * constructor(options) {\n * super(options);\n * this.queryManager[Symbol.for(\"apollo.hook.wrappers\")] = {\n * useQuery: (original) => (query, options) => {\n * console.log(\"useQuery was called with options\", options);\n * return original(query, options);\n * }\n * }\n * }\n * }\n *\n * // this will now log the options and then call the original `useQuery`\n * const client = new ApolloClientWithStreaming({ ... });\n * useQuery(query, { client });\n * ```\n */\nexport function wrapHook(hookName, useHook, clientOrObsQuery) {\n var queryManager = clientOrObsQuery[\"queryManager\"];\n var wrappers = queryManager && queryManager[wrapperSymbol];\n var wrapper = wrappers && wrappers[hookName];\n return wrapper ? wrapper(useHook) : useHook;\n}\n//# sourceMappingURL=wrapHook.js.map","import { __assign } from \"tslib\";\nimport { InternalQueryReference, wrapQueryRef } from \"../internal/index.js\";\nimport { wrapHook } from \"../hooks/internal/index.js\";\n/**\n * A higher order function that returns a `preloadQuery` function which\n * can be used to begin loading a query with the given `client`. This is useful\n * when you want to start loading a query as early as possible outside of a\n * React component.\n *\n * > Refer to the [Suspense - Initiating queries outside React](https://www.apollographql.com/docs/react/data/suspense#initiating-queries-outside-react) section for a more in-depth overview.\n *\n * @param client - The `ApolloClient` instance that will be used to load queries\n * from the returned `preloadQuery` function.\n * @returns The `preloadQuery` function.\n *\n * @example\n * ```js\n * const preloadQuery = createQueryPreloader(client);\n * ```\n * @since 3.9.0\n */\nexport function createQueryPreloader(client) {\n return wrapHook(\"createQueryPreloader\", _createQueryPreloader, client)(client);\n}\nvar _createQueryPreloader = function (client) {\n
|
|
1
|
+
{"version":3,"file":"react.cjs","sources":["../utilities/deprecation/index.js","hooks/internal/wrapHook.js","query-preloader/createQueryPreloader.js"],"sourcesContent":["import { __spreadArray } from \"tslib\";\nimport { Slot } from \"optimism\";\nimport { invariant } from \"../globals/index.js\";\nvar slot = new Slot();\nfunction isMuted(name) {\n return (slot.getValue() || []).includes(name);\n}\nexport function muteDeprecations(name) {\n var args = [];\n for (var _i = 1; _i < arguments.length; _i++) {\n args[_i - 1] = arguments[_i];\n }\n return slot.withValue.apply(slot, __spreadArray([Array.isArray(name) ? name : [name]], args, false));\n}\nexport function warnRemovedOption(options, name, callSite, recommendation) {\n if (recommendation === void 0) { recommendation = \"Please remove this option.\"; }\n warnDeprecated(name, function () {\n if (name in options) {\n globalThis.__DEV__ !== false && invariant.warn(91, callSite, name, recommendation);\n }\n });\n}\nexport function warnDeprecated(name, cb) {\n if (!isMuted(name)) {\n cb();\n }\n}\n//# sourceMappingURL=index.js.map","var wrapperSymbol = Symbol.for(\"apollo.hook.wrappers\");\n/**\n * @internal\n *\n * Makes an Apollo Client hook \"wrappable\".\n * That means that the Apollo Client instance can expose a \"wrapper\" that will be\n * used to wrap the original hook implementation with additional logic.\n * @example\n * ```tsx\n * // this is already done in `@apollo/client` for all wrappable hooks (see `WrappableHooks`)\n * // following this pattern\n * function useQuery() {\n * return wrapHook('useQuery', _useQuery, options.client)(query, options);\n * }\n * function _useQuery(query, options) {\n * // original implementation\n * }\n *\n * // this is what a library like `@apollo/client-react-streaming` would do\n * class ApolloClientWithStreaming extends ApolloClient {\n * constructor(options) {\n * super(options);\n * this.queryManager[Symbol.for(\"apollo.hook.wrappers\")] = {\n * useQuery: (original) => (query, options) => {\n * console.log(\"useQuery was called with options\", options);\n * return original(query, options);\n * }\n * }\n * }\n * }\n *\n * // this will now log the options and then call the original `useQuery`\n * const client = new ApolloClientWithStreaming({ ... });\n * useQuery(query, { client });\n * ```\n */\nexport function wrapHook(hookName, useHook, clientOrObsQuery) {\n var queryManager = clientOrObsQuery[\"queryManager\"];\n var wrappers = queryManager && queryManager[wrapperSymbol];\n var wrapper = wrappers && wrappers[hookName];\n return wrapper ? wrapper(useHook) : useHook;\n}\n//# sourceMappingURL=wrapHook.js.map","import { __assign } from \"tslib\";\nimport { InternalQueryReference, wrapQueryRef } from \"../internal/index.js\";\nimport { wrapHook } from \"../hooks/internal/index.js\";\nimport { muteDeprecations, warnRemovedOption, } from \"../../utilities/deprecation/index.js\";\n/**\n * A higher order function that returns a `preloadQuery` function which\n * can be used to begin loading a query with the given `client`. This is useful\n * when you want to start loading a query as early as possible outside of a\n * React component.\n *\n * > Refer to the [Suspense - Initiating queries outside React](https://www.apollographql.com/docs/react/data/suspense#initiating-queries-outside-react) section for a more in-depth overview.\n *\n * @param client - The `ApolloClient` instance that will be used to load queries\n * from the returned `preloadQuery` function.\n * @returns The `preloadQuery` function.\n *\n * @example\n * ```js\n * const preloadQuery = createQueryPreloader(client);\n * ```\n * @since 3.9.0\n */\nexport function createQueryPreloader(client) {\n return wrapHook(\"createQueryPreloader\", _createQueryPreloader, client)(client);\n}\nvar _createQueryPreloader = function (client) {\n function preloadQuery(query, options) {\n if (options === void 0) { options = Object.create(null); }\n warnRemovedOption(options, \"canonizeResults\", \"preloadQuery\");\n var queryRef = muteDeprecations(\"canonizeResults\", function () {\n var _a, _b;\n return new InternalQueryReference(client.watchQuery(__assign(__assign({}, options), { query: query })), {\n autoDisposeTimeoutMs: (_b = (_a = client.defaultOptions.react) === null || _a === void 0 ? void 0 : _a.suspense) === null || _b === void 0 ? void 0 : _b.autoDisposeTimeoutMs,\n });\n });\n return wrapQueryRef(queryRef);\n }\n return Object.assign(preloadQuery, {\n toPromise: function (queryRef) {\n return queryRef.toPromise();\n },\n });\n};\n//# sourceMappingURL=createQueryPreloader.js.map"],"names":["Slot","__spreadArray","invariant","InternalQueryReference","__assign","wrapQueryRef"],"mappings":";;;;;;;;;;;;AAGA,IAAI,IAAI,GAAG,IAAIA,aAAI,EAAE,CAAC;AACtB,SAAS,OAAO,CAAC,IAAI,EAAE;AACvB,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC;AACM,SAAS,gBAAgB,CAAC,IAAI,EAAE;AACvC,IAAI,IAAI,IAAI,GAAG,EAAE,CAAC;AAClB,IAAI,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE;AAClD,QAAQ,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;AACrC,KAAK;AACL,IAAI,OAAO,IAAI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CAAC,CAAC;AACP,CAAC;;;;;;;;;;;;;;"}
|
|
@@ -2,12 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
require('../utilities/globals');
|
|
5
|
+
var globals = require('../utilities/globals');
|
|
6
6
|
var context = require('./context');
|
|
7
7
|
var hooks = require('./hooks');
|
|
8
8
|
var parser = require('./parser');
|
|
9
9
|
var tslib = require('tslib');
|
|
10
10
|
var internal = require('./internal');
|
|
11
|
+
var optimism = require('optimism');
|
|
12
|
+
|
|
13
|
+
var slot = new optimism.Slot();
|
|
14
|
+
function isMuted(name) {
|
|
15
|
+
return (slot.getValue() || []).includes(name);
|
|
16
|
+
}
|
|
17
|
+
function muteDeprecations(name) {
|
|
18
|
+
var args = [];
|
|
19
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
20
|
+
args[_i - 1] = arguments[_i];
|
|
21
|
+
}
|
|
22
|
+
return slot.withValue.apply(slot, tslib.__spreadArray([Array.isArray(name) ? name : [name]], args, false));
|
|
23
|
+
}
|
|
24
|
+
function warnRemovedOption(options, name, callSite, recommendation) {
|
|
25
|
+
if (recommendation === void 0) { recommendation = "Please remove this option."; }
|
|
26
|
+
warnDeprecated(name, function () {
|
|
27
|
+
if (name in options) {
|
|
28
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(91, callSite, name, recommendation);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function warnDeprecated(name, cb) {
|
|
33
|
+
if (!isMuted(name)) {
|
|
34
|
+
cb();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
11
37
|
|
|
12
38
|
var wrapperSymbol = Symbol.for("apollo.hook.wrappers");
|
|
13
39
|
function wrapHook(hookName, useHook, clientOrObsQuery) {
|
|
@@ -21,14 +47,22 @@ function createQueryPreloader(client) {
|
|
|
21
47
|
return wrapHook("createQueryPreloader", _createQueryPreloader, client)(client);
|
|
22
48
|
}
|
|
23
49
|
var _createQueryPreloader = function (client) {
|
|
24
|
-
|
|
25
|
-
var _a, _b;
|
|
50
|
+
function preloadQuery(query, options) {
|
|
26
51
|
if (options === void 0) { options = Object.create(null); }
|
|
27
|
-
|
|
28
|
-
|
|
52
|
+
warnRemovedOption(options, "canonizeResults", "preloadQuery");
|
|
53
|
+
var queryRef = muteDeprecations("canonizeResults", function () {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
return new internal.InternalQueryReference(client.watchQuery(tslib.__assign(tslib.__assign({}, options), { query: query })), {
|
|
56
|
+
autoDisposeTimeoutMs: (_b = (_a = client.defaultOptions.react) === null || _a === void 0 ? void 0 : _a.suspense) === null || _b === void 0 ? void 0 : _b.autoDisposeTimeoutMs,
|
|
57
|
+
});
|
|
29
58
|
});
|
|
30
59
|
return internal.wrapQueryRef(queryRef);
|
|
31
|
-
}
|
|
60
|
+
}
|
|
61
|
+
return Object.assign(preloadQuery, {
|
|
62
|
+
toPromise: function (queryRef) {
|
|
63
|
+
return queryRef.toPromise();
|
|
64
|
+
},
|
|
65
|
+
});
|
|
32
66
|
};
|
|
33
67
|
|
|
34
68
|
exports.ApolloConsumer = context.ApolloConsumer;
|