@apollo/client 3.9.7 → 3.10.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.changeset/flat-singers-kiss.md +5 -0
  2. package/.changeset/pre.json +11 -0
  3. package/.changeset/tasty-pillows-ring.md +5 -0
  4. package/CHANGELOG.md +12 -0
  5. package/apollo-client.cjs +46 -10
  6. package/apollo-client.cjs.map +1 -1
  7. package/apollo-client.min.cjs +1 -1
  8. package/cache/cache.cjs +27 -0
  9. package/cache/cache.cjs.map +1 -1
  10. package/cache/cache.cjs.native.js +27 -0
  11. package/cache/core/cache.d.ts +83 -1
  12. package/cache/core/cache.js +30 -1
  13. package/cache/core/cache.js.map +1 -1
  14. package/core/ApolloClient.d.ts +26 -8
  15. package/core/ApolloClient.js +26 -7
  16. package/core/ApolloClient.js.map +1 -1
  17. package/core/core.cjs +4 -1
  18. package/core/core.cjs.map +1 -1
  19. package/core/core.cjs.native.js +4 -1
  20. package/core/watchQueryOptions.d.ts +3 -3
  21. package/dev/dev.cjs +1 -1
  22. package/dev/dev.cjs.map +1 -1
  23. package/dev/dev.cjs.native.js +1 -1
  24. package/package.json +17 -17
  25. package/react/hooks/hooks.cjs +26 -17
  26. package/react/hooks/hooks.cjs.map +1 -1
  27. package/react/hooks/hooks.cjs.native.js +26 -17
  28. package/react/hooks/useFragment.d.ts +1 -1
  29. package/react/hooks/useFragment.js +22 -14
  30. package/react/hooks/useFragment.js.map +1 -1
  31. package/react/internal/cache/QueryReference.d.ts +2 -2
  32. package/react/internal/cache/QueryReference.js.map +1 -1
  33. package/react/query-preloader/createQueryPreloader.d.ts +6 -6
  34. package/react/query-preloader/createQueryPreloader.js.map +1 -1
  35. package/react/types/types.d.ts +3 -3
  36. package/react/types/types.documentation.d.ts +4 -4
  37. package/react/types/types.documentation.js.map +1 -1
  38. package/utilities/globals/globals.cjs +1 -1
  39. package/utilities/globals/globals.cjs.map +1 -1
  40. package/utilities/globals/globals.cjs.native.js +1 -1
  41. package/version.js +1 -1
@@ -7,13 +7,15 @@ var React = require('rehackt');
7
7
  var context = require('../context');
8
8
  var tslib = require('tslib');
9
9
  var utilities = require('../../utilities');
10
- var equality = require('@wry/equality');
10
+ var equal = require('@wry/equality');
11
11
  var errors = require('../../errors');
12
12
  var core = require('../../core');
13
13
  var parser = require('../parser');
14
14
  var internal = require('../internal');
15
15
  var cache = require('../../cache');
16
16
 
17
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
18
+
17
19
  function _interopNamespace(e) {
18
20
  if (e && e.__esModule) return e;
19
21
  var n = Object.create(null);
@@ -27,6 +29,7 @@ function _interopNamespace(e) {
27
29
  }
28
30
 
29
31
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
32
+ var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
30
33
 
31
34
  function useApolloClient(override) {
32
35
  var context$1 = React__namespace.useContext(context.getApolloContext());
@@ -86,7 +89,7 @@ function checkIfSnapshotChanged(_a) {
86
89
 
87
90
  function useDeepMemo(memoFn, deps) {
88
91
  var ref = React__namespace.useRef();
89
- if (!ref.current || !equality.equal(ref.current.deps, deps)) {
92
+ if (!ref.current || !equal.equal(ref.current.deps, deps)) {
90
93
  ref.current = { value: memoFn(), deps: deps };
91
94
  }
92
95
  return ref.current.value;
@@ -226,7 +229,7 @@ var InternalState = (function () {
226
229
  if (previousResult &&
227
230
  previousResult.loading === result.loading &&
228
231
  previousResult.networkStatus === result.networkStatus &&
229
- equality.equal(previousResult.data, result.data)) {
232
+ equal.equal(previousResult.data, result.data)) {
230
233
  return;
231
234
  }
232
235
  _this.setResult(result);
@@ -240,7 +243,7 @@ var InternalState = (function () {
240
243
  var previousResult = _this.result;
241
244
  if (!previousResult ||
242
245
  (previousResult && previousResult.loading) ||
243
- !equality.equal(error, previousResult.error)) {
246
+ !equal.equal(error, previousResult.error)) {
244
247
  _this.setResult({
245
248
  data: (previousResult && previousResult.data),
246
249
  error: error,
@@ -266,7 +269,7 @@ var InternalState = (function () {
266
269
  var _a;
267
270
  var watchQueryOptions = this.createWatchQueryOptions((this.queryHookOptions = options));
268
271
  var currentWatchQueryOptions = this.watchQueryOptions;
269
- if (!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
272
+ if (!equal.equal(watchQueryOptions, currentWatchQueryOptions)) {
270
273
  this.watchQueryOptions = watchQueryOptions;
271
274
  if (currentWatchQueryOptions && this.observable) {
272
275
  this.observable.reobserve(this.getObsQueryOptions());
@@ -545,7 +548,7 @@ function useMutation(mutation, options) {
545
548
  error: error,
546
549
  client: client,
547
550
  };
548
- if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
551
+ if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
549
552
  setResult((ref.current.result = result_1));
550
553
  }
551
554
  }
@@ -565,7 +568,7 @@ function useMutation(mutation, options) {
565
568
  called: true,
566
569
  client: client,
567
570
  };
568
- if (!equality.equal(ref.current.result, result_2)) {
571
+ if (!equal.equal(ref.current.result, result_2)) {
569
572
  setResult((ref.current.result = result_2));
570
573
  }
571
574
  }
@@ -654,7 +657,7 @@ function useSubscription(subscription, options) {
654
657
  subscription !== ref.current.subscription ||
655
658
  (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
656
659
  !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
657
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
660
+ !equal.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
658
661
  canResetObservableRef.current) {
659
662
  setResult({
660
663
  loading: true,
@@ -758,21 +761,27 @@ function _useFragment(options) {
758
761
  var resultRef = useLazyRef(function () {
759
762
  return diffToResult(cache.diff(diffOptions));
760
763
  });
764
+ var stableOptions = useDeepMemo(function () { return options; }, [options]);
765
+ React__namespace.useMemo(function () {
766
+ resultRef.current = diffToResult(cache.diff(diffOptions));
767
+ }, [diffOptions, cache]);
761
768
  var getSnapshot = React__namespace.useCallback(function () { return resultRef.current; }, []);
762
769
  return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
763
770
  var lastTimeout = 0;
764
- var unsubscribe = cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
765
- if (!equality.equal(diff.result, resultRef.current.data)) {
766
- resultRef.current = diffToResult(diff);
767
- clearTimeout(lastTimeout);
768
- lastTimeout = setTimeout(forceUpdate);
769
- }
770
- } }));
771
+ var subscription = cache.watchFragment(stableOptions).subscribe({
772
+ next: function (result) {
773
+ if (equal__default(result, resultRef.current))
774
+ return;
775
+ resultRef.current = result;
776
+ clearTimeout(lastTimeout);
777
+ lastTimeout = setTimeout(forceUpdate);
778
+ },
779
+ });
771
780
  return function () {
772
- unsubscribe();
781
+ subscription.unsubscribe();
773
782
  clearTimeout(lastTimeout);
774
783
  };
775
- }, [cache, diffOptions]), getSnapshot, getSnapshot);
784
+ }, [cache, stableOptions]), getSnapshot, getSnapshot);
776
785
  }
777
786
  function diffToResult(diff) {
778
787
  var result = {
@@ -6,7 +6,7 @@ export interface UseFragmentOptions<TData, TVars> extends Omit<Cache.DiffOptions
6
6
  from: StoreObject | Reference | string;
7
7
  optimistic?: boolean;
8
8
  /**
9
- * The instance of {@link ApolloClient} to use to look up the fragment.
9
+ * The instance of `ApolloClient` to use to look up the fragment.
10
10
  *
11
11
  * By default, the instance that's passed down via context is used, but you
12
12
  * can provide a different instance here.
@@ -1,10 +1,10 @@
1
1
  import { __assign, __rest } from "tslib";
2
2
  import * as React from "rehackt";
3
- import { equal } from "@wry/equality";
4
3
  import { mergeDeepArray } from "../../utilities/index.js";
5
4
  import { useApolloClient } from "./useApolloClient.js";
6
5
  import { useSyncExternalStore } from "./useSyncExternalStore.js";
7
6
  import { useDeepMemo, useLazyRef, wrapHook } from "./internal/index.js";
7
+ import equal from "@wry/equality";
8
8
  export function useFragment(options) {
9
9
  return wrapHook("useFragment", _useFragment, useApolloClient(options.client))(options);
10
10
  }
@@ -17,26 +17,34 @@ function _useFragment(options) {
17
17
  var resultRef = useLazyRef(function () {
18
18
  return diffToResult(cache.diff(diffOptions));
19
19
  });
20
+ var stableOptions = useDeepMemo(function () { return options; }, [options]);
21
+ // Since .next is async, we need to make sure that we
22
+ // get the correct diff on the next render given new diffOptions
23
+ React.useMemo(function () {
24
+ resultRef.current = diffToResult(cache.diff(diffOptions));
25
+ }, [diffOptions, cache]);
20
26
  // Used for both getSnapshot and getServerSnapshot
21
27
  var getSnapshot = React.useCallback(function () { return resultRef.current; }, []);
22
28
  return useSyncExternalStore(React.useCallback(function (forceUpdate) {
23
29
  var lastTimeout = 0;
24
- var unsubscribe = cache.watch(__assign(__assign({}, diffOptions), { immediate: true, callback: function (diff) {
25
- if (!equal(diff.result, resultRef.current.data)) {
26
- resultRef.current = diffToResult(diff);
27
- // If we get another update before we've re-rendered, bail out of
28
- // the update and try again. This ensures that the relative timing
29
- // between useQuery and useFragment stays roughly the same as
30
- // fixed in https://github.com/apollographql/apollo-client/pull/11083
31
- clearTimeout(lastTimeout);
32
- lastTimeout = setTimeout(forceUpdate);
33
- }
34
- } }));
30
+ var subscription = cache.watchFragment(stableOptions).subscribe({
31
+ next: function (result) {
32
+ if (equal(result, resultRef.current))
33
+ return;
34
+ resultRef.current = result;
35
+ // If we get another update before we've re-rendered, bail out of
36
+ // the update and try again. This ensures that the relative timing
37
+ // between useQuery and useFragment stays roughly the same as
38
+ // fixed in https://github.com/apollographql/apollo-client/pull/11083
39
+ clearTimeout(lastTimeout);
40
+ lastTimeout = setTimeout(forceUpdate);
41
+ },
42
+ });
35
43
  return function () {
36
- unsubscribe();
44
+ subscription.unsubscribe();
37
45
  clearTimeout(lastTimeout);
38
46
  };
39
- }, [cache, diffOptions]), getSnapshot, getSnapshot);
47
+ }, [cache, stableOptions]), getSnapshot, getSnapshot);
40
48
  }
41
49
  function diffToResult(diff) {
42
50
  var result = {
@@ -1 +1 @@
1
- {"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAQ1D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAqCxE,MAAM,UAAU,WAAW,CACzB,OAAyC;IAEzC,OAAO,QAAQ,CACb,aAAa,EACb,YAAY,EACZ,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAChC,CAAC,OAAO,CAAC,CAAC;AACb,CAAC;AAED,SAAS,YAAY,CACnB,OAAyC;IAEjC,IAAA,KAAK,GAAK,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,MAApC,CAAqC;IAElD,IAAM,WAAW,GAAG,WAAW,CAAkC;QAE7D,IAAA,QAAQ,GAKN,OAAO,SALD,EACR,YAAY,GAIV,OAAO,aAJG,EACZ,IAAI,GAGF,OAAO,KAHL,EACJ,KAEE,OAAO,WAFQ,EAAjB,UAAU,mBAAG,IAAI,KAAA,EACd,IAAI,UACL,OAAO,EANL,kDAML,CADQ,CACG;QAEZ,6BACK,IAAI,KACP,iBAAiB,EAAE,IAAI,EACvB,EAAE,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC1D,KAAK,EAAE,KAAK,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AE,CAAC,CAAC,IAAI,CAAC,QAAQ;KACE,CAAC;IAE9B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport { equal } from \"@wry/equality\";\n\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport { mergeDeepArray } from \"../../utilities/index.js\";\nimport type {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache/index.js\";\n\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport type { ApolloClient, OperationVariables } from \"../../core/index.js\";\nimport type { NoInfer } from \"../types/types.js\";\nimport { useDeepMemo, useLazyRef, wrapHook } from \"./internal/index.js\";\n\nexport interface UseFragmentOptions<TData, TVars>\n extends Omit<\n Cache.DiffOptions<NoInfer<TData>, NoInfer<TVars>>,\n \"id\" | \"query\" | \"optimistic\" | \"previousResult\" | \"returnPartialData\"\n >,\n Omit<\n Cache.ReadFragmentOptions<TData, TVars>,\n \"id\" | \"variables\" | \"returnPartialData\"\n > {\n from: StoreObject | Reference | string;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n /**\n * The instance of {@link ApolloClient} to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient<any>;\n}\n\nexport type UseFragmentResult<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 function useFragment<TData = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<TData> {\n return wrapHook(\n \"useFragment\",\n _useFragment,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction _useFragment<TData = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<TData> {\n const { cache } = useApolloClient(options.client);\n\n const diffOptions = useDeepMemo<Cache.DiffOptions<TData, TVars>>(() => {\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...rest\n } = options;\n\n return {\n ...rest,\n returnPartialData: true,\n id: typeof from === \"string\" ? from : cache.identify(from),\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n };\n }, [options]);\n\n const resultRef = useLazyRef<UseFragmentResult<TData>>(() =>\n diffToResult(cache.diff<TData>(diffOptions))\n );\n\n // Used for both getSnapshot and getServerSnapshot\n const getSnapshot = React.useCallback(() => resultRef.current, []);\n\n return useSyncExternalStore(\n React.useCallback(\n (forceUpdate) => {\n let lastTimeout = 0;\n const unsubscribe = cache.watch({\n ...diffOptions,\n immediate: true,\n callback(diff) {\n if (!equal(diff.result, resultRef.current.data)) {\n resultRef.current = diffToResult(diff);\n // If we get another update before we've re-rendered, bail out of\n // the update and try again. This ensures that the relative timing\n // between useQuery and useFragment stays roughly the same as\n // fixed in https://github.com/apollographql/apollo-client/pull/11083\n clearTimeout(lastTimeout);\n lastTimeout = setTimeout(forceUpdate) as any;\n }\n },\n });\n return () => {\n unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [cache, diffOptions]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>\n): UseFragmentResult<TData> {\n const result = {\n data: diff.result!,\n complete: !!diff.complete,\n } as UseFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(diff.missing.map((error) => error.missing));\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,M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,IAAI,CAAC,MAAO;QAClB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;KACE,CAAC;IAE9B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport { mergeDeepArray } from \"../../utilities/index.js\";\nimport type {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache/index.js\";\n\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport type { ApolloClient, OperationVariables } from \"../../core/index.js\";\nimport type { NoInfer } from \"../types/types.js\";\nimport { useDeepMemo, useLazyRef, wrapHook } from \"./internal/index.js\";\nimport equal from \"@wry/equality\";\n\nexport interface UseFragmentOptions<TData, TVars>\n extends Omit<\n Cache.DiffOptions<NoInfer<TData>, NoInfer<TVars>>,\n \"id\" | \"query\" | \"optimistic\" | \"previousResult\" | \"returnPartialData\"\n >,\n Omit<\n Cache.ReadFragmentOptions<TData, TVars>,\n \"id\" | \"variables\" | \"returnPartialData\"\n > {\n from: StoreObject | Reference | string;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n /**\n * The instance of `ApolloClient` to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient<any>;\n}\n\nexport type UseFragmentResult<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 function useFragment<TData = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<TData> {\n return wrapHook(\n \"useFragment\",\n _useFragment,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction _useFragment<TData = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<TData> {\n const { cache } = useApolloClient(options.client);\n\n const diffOptions = useDeepMemo<Cache.DiffOptions<TData, TVars>>(() => {\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...rest\n } = options;\n\n return {\n ...rest,\n returnPartialData: true,\n id: typeof from === \"string\" ? from : cache.identify(from),\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n };\n }, [options]);\n\n const resultRef = useLazyRef<UseFragmentResult<TData>>(() =>\n diffToResult(cache.diff<TData>(diffOptions))\n );\n\n const stableOptions = useDeepMemo(() => options, [options]);\n\n // Since .next is async, we need to make sure that we\n // get the correct diff on the next render given new diffOptions\n React.useMemo(() => {\n resultRef.current = diffToResult(cache.diff<TData>(diffOptions));\n }, [diffOptions, cache]);\n\n // Used for both getSnapshot and getServerSnapshot\n const getSnapshot = React.useCallback(() => resultRef.current, []);\n\n return useSyncExternalStore(\n React.useCallback(\n (forceUpdate) => {\n let lastTimeout = 0;\n const subscription = cache.watchFragment(stableOptions).subscribe({\n next: (result) => {\n if (equal(result, resultRef.current)) return;\n resultRef.current = result;\n // If we get another update before we've re-rendered, bail out of\n // the update and try again. This ensures that the relative timing\n // between useQuery and useFragment stays roughly the same as\n // fixed in https://github.com/apollographql/apollo-client/pull/11083\n clearTimeout(lastTimeout);\n lastTimeout = setTimeout(forceUpdate) as any;\n },\n });\n return () => {\n subscription.unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [cache, stableOptions]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>\n): UseFragmentResult<TData> {\n const result = {\n data: diff.result!,\n complete: !!diff.complete,\n } as UseFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(diff.missing.map((error) => error.missing));\n }\n\n return result;\n}\n"]}
@@ -7,8 +7,8 @@ type FetchMoreOptions<TData> = Parameters<ObservableQuery<TData>["fetchMore"]>[0
7
7
  declare const QUERY_REFERENCE_SYMBOL: unique symbol;
8
8
  declare const PROMISE_SYMBOL: unique symbol;
9
9
  /**
10
- * A `QueryReference` is an opaque object returned by {@link useBackgroundQuery}.
11
- * A child component reading the `QueryReference` via {@link useReadQuery} will
10
+ * A `QueryReference` is an opaque object returned by `useBackgroundQuery`.
11
+ * A child component reading the `QueryReference` via `useReadQuery` will
12
12
  * suspend until the promise resolves.
13
13
  */
14
14
  export interface QueryReference<TData = unknown, TVariables = unknown> {
@@ -1 +1 @@
1
- {"version":3,"file":"QueryReference.js","sourceRoot":"","sources":["../../../../src/react/internal/cache/QueryReference.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAYtC,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAUnE,IAAM,sBAAsB,GAAkB,MAAM,EAAE,CAAC;AACvD,IAAM,cAAc,GAAkB,MAAM,EAAE,CAAC;AAyD/C,MAAM,UAAU,YAAY,CAC1B,gBAA+C;;IAE/C,IAAM,GAAG;YACP,SAAS;gBACP,yEAAyE;gBACzE,wEAAwE;gBACxE,sEAAsE;gBACtE,+DAA+D;gBAC/D,EAAE;gBACF,yEAAyE;gBACzE,kEAAkE;gBAClE,EAAE;gBACF,sBAAsB;gBACtB,+DAA+D;gBAC/D,IAAI;gBACJ,OAAO,iBAAiB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAM,OAAA,GAAG,EAAH,CAAG,CAAC,CAAC;YAChD,CAAC;;QACD,GAAC,sBAAsB,IAAG,gBAAgB;QAC1C,GAAC,cAAc,IAAG,gBAAgB,CAAC,OAAO;WAC3C,CAAC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AAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAI,CAAC,MAAM,CAAC,EAAtD,CAAsD,CACnE;aACA,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;IAEO,0CAAS,GAAjB;QACE,2EAA2E;QAC3E,yBAAyB;QACzB,IAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;QAEvD,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YAC/B,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO;YACV,CACE,MAAM,CAAC,IAAI;gBACX,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAC9D,CAAC,CAAC;gBACD,sBAAsB,CAAC,MAAM,CAAC;gBAChC,CAAC,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAClC,CAAC;IAEO,qDAAoB,GAA5B;QAAA,iBAOC;QANC,OAAO,oBAAoB,CACzB,IAAI,OAAO,CAA2B,UAAC,OAAO,EAAE,MAAM;YACpD,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IACH,6BAAC;AAAD,CAAC,AApSD,IAoSC","sourcesContent":["import { equal } from \"@wry/equality\";\nimport type {\n ApolloError,\n ApolloQueryResult,\n ObservableQuery,\n OperationVariables,\n WatchQueryOptions,\n} from \"../../../core/index.js\";\nimport type {\n ObservableSubscription,\n PromiseWithState,\n} from \"../../../utilities/index.js\";\nimport {\n createFulfilledPromise,\n createRejectedPromise,\n} from \"../../../utilities/index.js\";\nimport type { QueryKey } from \"./types.js\";\nimport type { useBackgroundQuery, useReadQuery } from \"../../hooks/index.js\";\nimport { wrapPromiseWithState } from \"../../../utilities/index.js\";\n\ntype QueryRefPromise<TData> = PromiseWithState<ApolloQueryResult<TData>>;\n\ntype Listener<TData> = (promise: QueryRefPromise<TData>) => void;\n\ntype FetchMoreOptions<TData> = Parameters<\n ObservableQuery<TData>[\"fetchMore\"]\n>[0];\n\nconst QUERY_REFERENCE_SYMBOL: unique symbol = Symbol();\nconst PROMISE_SYMBOL: unique symbol = Symbol();\n\n/**\n * A `QueryReference` is an opaque object returned by {@link useBackgroundQuery}.\n * A child component reading the `QueryReference` via {@link useReadQuery} will\n * suspend until the promise resolves.\n */\nexport interface QueryReference<TData = unknown, TVariables = unknown> {\n /** @internal */\n readonly [QUERY_REFERENCE_SYMBOL]: InternalQueryReference<TData>;\n /** @internal */\n [PROMISE_SYMBOL]: QueryRefPromise<TData>;\n /**\n * A function that returns a promise that resolves when the query has finished\n * loading. The promise resolves with the `QueryReference` itself.\n *\n * @remarks\n * This method is useful for preloading queries in data loading routers, such\n * as [React Router](https://reactrouter.com/en/main) or [TanStack Router](https://tanstack.com/router),\n * to prevent routes from transitioning until the query has finished loading.\n * `data` is not exposed on the promise to discourage using the data in\n * `loader` functions and exposing it to your route components. Instead, we\n * prefer you rely on `useReadQuery` to access the data to ensure your\n * component can rerender with cache updates. If you need to access raw query\n * data, use `client.query()` directly.\n *\n * @example\n * Here's an example using React Router's `loader` function:\n * ```ts\n * import { createQueryPreloader } from \"@apollo/client\";\n *\n * const preloadQuery = createQueryPreloader(client);\n *\n * export async function loader() {\n * const queryRef = preloadQuery(GET_DOGS_QUERY);\n *\n * return queryRef.toPromise();\n * }\n *\n * export function RouteComponent() {\n * const queryRef = useLoaderData();\n * const { data } = useReadQuery(queryRef);\n *\n * // ...\n * }\n * ```\n *\n * @alpha\n */\n toPromise(): Promise<QueryReference<TData, TVariables>>;\n}\n\ninterface InternalQueryReferenceOptions {\n onDispose?: () => void;\n autoDisposeTimeoutMs?: number;\n}\n\nexport function wrapQueryRef<TData, TVariables extends OperationVariables>(\n internalQueryRef: InternalQueryReference<TData>\n) {\n const ref: QueryReference<TData, TVariables> = {\n toPromise() {\n // We avoid resolving this promise with the query data because we want to\n // discourage using the server data directly from the queryRef. Instead,\n // the data should be accessed through `useReadQuery`. When the server\n // data is needed, its better to use `client.query()` directly.\n //\n // Here we resolve with the ref itself to make using this in React Router\n // or TanStack Router `loader` functions a bit more ergonomic e.g.\n //\n // function loader() {\n // return { queryRef: await preloadQuery(query).toPromise() }\n // }\n return getWrappedPromise(ref).then(() => ref);\n },\n [QUERY_REFERENCE_SYMBOL]: internalQueryRef,\n [PROMISE_SYMBOL]: internalQueryRef.promise,\n };\n\n return ref;\n}\n\nexport function getWrappedPromise<TData>(queryRef: QueryReference<TData, any>) {\n const internalQueryRef = unwrapQueryRef(queryRef);\n\n return internalQueryRef.promise.status === \"fulfilled\" ?\n internalQueryRef.promise\n : queryRef[PROMISE_SYMBOL];\n}\n\nexport function unwrapQueryRef<TData>(\n queryRef: QueryReference<TData>\n): InternalQueryReference<TData> {\n return queryRef[QUERY_REFERENCE_SYMBOL];\n}\n\nexport function updateWrappedQueryRef<TData>(\n queryRef: QueryReference<TData>,\n promise: QueryRefPromise<TData>\n) {\n queryRef[PROMISE_SYMBOL] = promise;\n}\n\nconst OBSERVED_CHANGED_OPTIONS = [\n \"canonizeResults\",\n \"context\",\n \"errorPolicy\",\n \"fetchPolicy\",\n \"refetchWritePolicy\",\n \"returnPartialData\",\n] as const;\n\ntype ObservedOptions = Pick<\n WatchQueryOptions,\n (typeof OBSERVED_CHANGED_OPTIONS)[number]\n>;\n\nexport class InternalQueryReference<TData = unknown> {\n public result!: ApolloQueryResult<TData>;\n public readonly key: QueryKey = {};\n public readonly observable: ObservableQuery<TData>;\n\n public promise!: QueryRefPromise<TData>;\n\n private subscription!: ObservableSubscription;\n private listeners = new Set<Listener<TData>>();\n private autoDisposeTimeoutId?: NodeJS.Timeout;\n\n private resolve: ((result: ApolloQueryResult<TData>) => void) | undefined;\n private reject: ((error: unknown) => void) | undefined;\n\n private references = 0;\n\n constructor(\n observable: ObservableQuery<TData, any>,\n options: InternalQueryReferenceOptions\n ) {\n this.handleNext = this.handleNext.bind(this);\n this.handleError = this.handleError.bind(this);\n this.dispose = this.dispose.bind(this);\n this.observable = observable;\n\n if (options.onDispose) {\n this.onDispose = options.onDispose;\n }\n\n this.setResult();\n this.subscribeToQuery();\n\n // Start a timer that will automatically dispose of the query if the\n // suspended resource does not use this queryRef in the given time. This\n // helps prevent memory leaks when a component has unmounted before the\n // query has finished loading.\n const startDisposeTimer = () => {\n if (!this.references) {\n this.autoDisposeTimeoutId = setTimeout(\n this.dispose,\n options.autoDisposeTimeoutMs ?? 30_000\n );\n }\n };\n\n // We wait until the request has settled to ensure we don't dispose of the\n // query ref before the request finishes, otherwise we would leave the\n // promise in a pending state rendering the suspense boundary indefinitely.\n this.promise.then(startDisposeTimer, startDisposeTimer);\n }\n\n get disposed() {\n return this.subscription.closed;\n }\n\n get watchQueryOptions() {\n return this.observable.options;\n }\n\n reinitialize() {\n const { observable } = this;\n\n const originalFetchPolicy = this.watchQueryOptions.fetchPolicy;\n\n try {\n if (originalFetchPolicy !== \"no-cache\") {\n observable.resetLastResults();\n observable.silentSetOptions({ fetchPolicy: \"cache-first\" });\n } else {\n observable.silentSetOptions({ fetchPolicy: \"standby\" });\n }\n\n this.subscribeToQuery();\n\n if (originalFetchPolicy === \"no-cache\") {\n return;\n }\n\n observable.resetDiff();\n this.setResult();\n } finally {\n observable.silentSetOptions({ fetchPolicy: originalFetchPolicy });\n }\n }\n\n retain() {\n this.references++;\n clearTimeout(this.autoDisposeTimeoutId);\n let disposed = false;\n\n return () => {\n if (disposed) {\n return;\n }\n\n disposed = true;\n this.references--;\n\n // Wait before fully disposing in case the app is running in strict mode.\n setTimeout(() => {\n if (!this.references) {\n this.dispose();\n }\n });\n };\n }\n\n didChangeOptions(watchQueryOptions: ObservedOptions) {\n return OBSERVED_CHANGED_OPTIONS.some(\n (option) =>\n !equal(this.watchQueryOptions[option], watchQueryOptions[option])\n );\n }\n\n applyOptions(watchQueryOptions: ObservedOptions) {\n const {\n fetchPolicy: currentFetchPolicy,\n canonizeResults: currentCanonizeResults,\n } = this.watchQueryOptions;\n\n // \"standby\" is used when `skip` is set to `true`. Detect when we've\n // enabled the query (i.e. `skip` is `false`) to execute a network request.\n if (\n currentFetchPolicy === \"standby\" &&\n currentFetchPolicy !== watchQueryOptions.fetchPolicy\n ) {\n this.initiateFetch(this.observable.reobserve(watchQueryOptions));\n } else {\n this.observable.silentSetOptions(watchQueryOptions);\n\n if (currentCanonizeResults !== watchQueryOptions.canonizeResults) {\n this.result = { ...this.result, ...this.observable.getCurrentResult() };\n this.promise = createFulfilledPromise(this.result);\n }\n }\n\n return this.promise;\n }\n\n listen(listener: Listener<TData>) {\n this.listeners.add(listener);\n\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n refetch(variables: OperationVariables | undefined) {\n return this.initiateFetch(this.observable.refetch(variables));\n }\n\n fetchMore(options: FetchMoreOptions<TData>) {\n return this.initiateFetch(this.observable.fetchMore<TData>(options));\n }\n\n private dispose() {\n this.subscription.unsubscribe();\n this.onDispose();\n }\n\n private onDispose() {\n // noop. overridable by options\n }\n\n private handleNext(result: ApolloQueryResult<TData>) {\n switch (this.promise.status) {\n case \"pending\": {\n // Maintain the last successful `data` value if the next result does not\n // have one.\n if (result.data === void 0) {\n result.data = this.result.data;\n }\n this.result = result;\n this.resolve?.(result);\n break;\n }\n default: {\n // This occurs when switching to a result that is fully cached when this\n // class is instantiated. ObservableQuery will run reobserve when\n // subscribing, which delivers a result from the cache.\n if (\n result.data === this.result.data &&\n result.networkStatus === this.result.networkStatus\n ) {\n return;\n }\n\n // Maintain the last successful `data` value if the next result does not\n // have one.\n if (result.data === void 0) {\n result.data = this.result.data;\n }\n\n this.result = result;\n this.promise = createFulfilledPromise(result);\n this.deliver(this.promise);\n break;\n }\n }\n }\n\n private handleError(error: ApolloError) {\n this.subscription.unsubscribe();\n this.subscription = this.observable.resubscribeAfterError(\n this.handleNext,\n this.handleError\n );\n\n switch (this.promise.status) {\n case \"pending\": {\n this.reject?.(error);\n break;\n }\n default: {\n this.promise = createRejectedPromise<ApolloQueryResult<TData>>(error);\n this.deliver(this.promise);\n }\n }\n }\n\n private deliver(promise: QueryRefPromise<TData>) {\n this.listeners.forEach((listener) => listener(promise));\n }\n\n private initiateFetch(returnedPromise: Promise<ApolloQueryResult<TData>>) {\n this.promise = this.createPendingPromise();\n this.promise.catch(() => {});\n\n // If the data returned from the fetch is deeply equal to the data already\n // in the cache, `handleNext` will not be triggered leaving the promise we\n // created in a pending state forever. To avoid this situtation, we attempt\n // to resolve the promise if `handleNext` hasn't been run to ensure the\n // promise is resolved correctly.\n returnedPromise\n .then((result) => {\n // In the case of `fetchMore`, this promise is resolved before a cache\n // result is emitted due to the fact that `fetchMore` sets a `no-cache`\n // fetch policy and runs `cache.batch` in its `.then` handler. Because\n // the timing is different, we accidentally run this update twice\n // causing an additional re-render with the `fetchMore` result by\n // itself. By wrapping in `setTimeout`, this should provide a short\n // delay to allow the `QueryInfo.notify` handler to run before this\n // promise is checked.\n // See https://github.com/apollographql/apollo-client/issues/11315 for\n // more information\n setTimeout(() => {\n if (this.promise.status === \"pending\") {\n this.result = result;\n this.resolve?.(result);\n }\n });\n })\n .catch(() => {});\n\n return returnedPromise;\n }\n\n private subscribeToQuery() {\n this.subscription = this.observable\n .filter(\n (result) => !equal(result.data, {}) && !equal(result, this.result)\n )\n .subscribe(this.handleNext, this.handleError);\n }\n\n private setResult() {\n // Don't save this result as last result to prevent delivery of last result\n // when first subscribing\n const result = this.observable.getCurrentResult(false);\n\n if (equal(result, this.result)) {\n return;\n }\n\n this.result = result;\n this.promise =\n (\n result.data &&\n (!result.partial || this.watchQueryOptions.returnPartialData)\n ) ?\n createFulfilledPromise(result)\n : this.createPendingPromise();\n }\n\n private createPendingPromise() {\n return wrapPromiseWithState(\n new Promise<ApolloQueryResult<TData>>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n })\n );\n }\n}\n"]}
1
+ {"version":3,"file":"QueryReference.js","sourceRoot":"","sources":["../../../../src/react/internal/cache/QueryReference.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAYtC,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAUnE,IAAM,sBAAsB,GAAkB,MAAM,EAAE,CAAC;AACvD,IAAM,cAAc,GAAkB,MAAM,EAAE,CAAC;AAyD/C,MAAM,UAAU,YAAY,CAC1B,gBAA+C;;IAE/C,IAAM,GAAG;YACP,SAAS;gBACP,yEAAyE;gBACzE,wEAAwE;gBACxE,sEAAsE;gBACtE,+DAA+D;gBAC/D,EAAE;gBACF,yEAAyE;gBACzE,kEAAkE;gBAClE,EAAE;gBACF,sBAAsB;gBACtB,+DAA+D;gBAC/D,IAAI;gBACJ,OAAO,iBAAiB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAM,OAAA,GAAG,EAAH,CAAG,CAAC,CAAC;YAChD,CAAC;;QACD,GAAC,sBAAsB,IAAG,gBAAgB;QAC1C,GAAC,cAAc,IAAG,gBAAgB,CAAC,OAAO;WAC3C,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAQ,QAAoC;IAC3E,IAAM,gBAAgB,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAElD,OAAO,gBAAgB,CAAC,OAAO,CAAC,MAAM,KAAK,WAAW,CAAC,CAAC;QACpD,gBAAgB,CAAC,OAAO;QAC1B,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,QAA+B;IAE/B,OAAO,QAAQ,CAAC,sBAAsB,CAAC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,EAAE,CAAC;YAC/B,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO;YACV,CACE,MAAM,CAAC,IAAI;gBACX,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAC9D,CAAC,CAAC;gBACD,sBAAsB,CAAC,MAAM,CAAC;gBAChC,CAAC,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAClC,CAAC;IAEO,qDAAoB,GAA5B;QAAA,iBAOC;QANC,OAAO,oBAAoB,CACzB,IAAI,OAAO,CAA2B,UAAC,OAAO,EAAE,MAAM;YACpD,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IACH,6BAAC;AAAD,CAAC,AApSD,IAoSC","sourcesContent":["import { equal } from \"@wry/equality\";\nimport type {\n ApolloError,\n ApolloQueryResult,\n ObservableQuery,\n OperationVariables,\n WatchQueryOptions,\n} from \"../../../core/index.js\";\nimport type {\n ObservableSubscription,\n PromiseWithState,\n} from \"../../../utilities/index.js\";\nimport {\n createFulfilledPromise,\n createRejectedPromise,\n} from \"../../../utilities/index.js\";\nimport type { QueryKey } from \"./types.js\";\nimport { wrapPromiseWithState } from \"../../../utilities/index.js\";\n\ntype QueryRefPromise<TData> = PromiseWithState<ApolloQueryResult<TData>>;\n\ntype Listener<TData> = (promise: QueryRefPromise<TData>) => void;\n\ntype FetchMoreOptions<TData> = Parameters<\n ObservableQuery<TData>[\"fetchMore\"]\n>[0];\n\nconst QUERY_REFERENCE_SYMBOL: unique symbol = Symbol();\nconst PROMISE_SYMBOL: unique symbol = Symbol();\n\n/**\n * A `QueryReference` is an opaque object returned by `useBackgroundQuery`.\n * A child component reading the `QueryReference` via `useReadQuery` will\n * suspend until the promise resolves.\n */\nexport interface QueryReference<TData = unknown, TVariables = unknown> {\n /** @internal */\n readonly [QUERY_REFERENCE_SYMBOL]: InternalQueryReference<TData>;\n /** @internal */\n [PROMISE_SYMBOL]: QueryRefPromise<TData>;\n /**\n * A function that returns a promise that resolves when the query has finished\n * loading. The promise resolves with the `QueryReference` itself.\n *\n * @remarks\n * This method is useful for preloading queries in data loading routers, such\n * as [React Router](https://reactrouter.com/en/main) or [TanStack Router](https://tanstack.com/router),\n * to prevent routes from transitioning until the query has finished loading.\n * `data` is not exposed on the promise to discourage using the data in\n * `loader` functions and exposing it to your route components. Instead, we\n * prefer you rely on `useReadQuery` to access the data to ensure your\n * component can rerender with cache updates. If you need to access raw query\n * data, use `client.query()` directly.\n *\n * @example\n * Here's an example using React Router's `loader` function:\n * ```ts\n * import { createQueryPreloader } from \"@apollo/client\";\n *\n * const preloadQuery = createQueryPreloader(client);\n *\n * export async function loader() {\n * const queryRef = preloadQuery(GET_DOGS_QUERY);\n *\n * return queryRef.toPromise();\n * }\n *\n * export function RouteComponent() {\n * const queryRef = useLoaderData();\n * const { data } = useReadQuery(queryRef);\n *\n * // ...\n * }\n * ```\n *\n * @alpha\n */\n toPromise(): Promise<QueryReference<TData, TVariables>>;\n}\n\ninterface InternalQueryReferenceOptions {\n onDispose?: () => void;\n autoDisposeTimeoutMs?: number;\n}\n\nexport function wrapQueryRef<TData, TVariables extends OperationVariables>(\n internalQueryRef: InternalQueryReference<TData>\n) {\n const ref: QueryReference<TData, TVariables> = {\n toPromise() {\n // We avoid resolving this promise with the query data because we want to\n // discourage using the server data directly from the queryRef. Instead,\n // the data should be accessed through `useReadQuery`. When the server\n // data is needed, its better to use `client.query()` directly.\n //\n // Here we resolve with the ref itself to make using this in React Router\n // or TanStack Router `loader` functions a bit more ergonomic e.g.\n //\n // function loader() {\n // return { queryRef: await preloadQuery(query).toPromise() }\n // }\n return getWrappedPromise(ref).then(() => ref);\n },\n [QUERY_REFERENCE_SYMBOL]: internalQueryRef,\n [PROMISE_SYMBOL]: internalQueryRef.promise,\n };\n\n return ref;\n}\n\nexport function getWrappedPromise<TData>(queryRef: QueryReference<TData, any>) {\n const internalQueryRef = unwrapQueryRef(queryRef);\n\n return internalQueryRef.promise.status === \"fulfilled\" ?\n internalQueryRef.promise\n : queryRef[PROMISE_SYMBOL];\n}\n\nexport function unwrapQueryRef<TData>(\n queryRef: QueryReference<TData>\n): InternalQueryReference<TData> {\n return queryRef[QUERY_REFERENCE_SYMBOL];\n}\n\nexport function updateWrappedQueryRef<TData>(\n queryRef: QueryReference<TData>,\n promise: QueryRefPromise<TData>\n) {\n queryRef[PROMISE_SYMBOL] = promise;\n}\n\nconst OBSERVED_CHANGED_OPTIONS = [\n \"canonizeResults\",\n \"context\",\n \"errorPolicy\",\n \"fetchPolicy\",\n \"refetchWritePolicy\",\n \"returnPartialData\",\n] as const;\n\ntype ObservedOptions = Pick<\n WatchQueryOptions,\n (typeof OBSERVED_CHANGED_OPTIONS)[number]\n>;\n\nexport class InternalQueryReference<TData = unknown> {\n public result!: ApolloQueryResult<TData>;\n public readonly key: QueryKey = {};\n public readonly observable: ObservableQuery<TData>;\n\n public promise!: QueryRefPromise<TData>;\n\n private subscription!: ObservableSubscription;\n private listeners = new Set<Listener<TData>>();\n private autoDisposeTimeoutId?: NodeJS.Timeout;\n\n private resolve: ((result: ApolloQueryResult<TData>) => void) | undefined;\n private reject: ((error: unknown) => void) | undefined;\n\n private references = 0;\n\n constructor(\n observable: ObservableQuery<TData, any>,\n options: InternalQueryReferenceOptions\n ) {\n this.handleNext = this.handleNext.bind(this);\n this.handleError = this.handleError.bind(this);\n this.dispose = this.dispose.bind(this);\n this.observable = observable;\n\n if (options.onDispose) {\n this.onDispose = options.onDispose;\n }\n\n this.setResult();\n this.subscribeToQuery();\n\n // Start a timer that will automatically dispose of the query if the\n // suspended resource does not use this queryRef in the given time. This\n // helps prevent memory leaks when a component has unmounted before the\n // query has finished loading.\n const startDisposeTimer = () => {\n if (!this.references) {\n this.autoDisposeTimeoutId = setTimeout(\n this.dispose,\n options.autoDisposeTimeoutMs ?? 30_000\n );\n }\n };\n\n // We wait until the request has settled to ensure we don't dispose of the\n // query ref before the request finishes, otherwise we would leave the\n // promise in a pending state rendering the suspense boundary indefinitely.\n this.promise.then(startDisposeTimer, startDisposeTimer);\n }\n\n get disposed() {\n return this.subscription.closed;\n }\n\n get watchQueryOptions() {\n return this.observable.options;\n }\n\n reinitialize() {\n const { observable } = this;\n\n const originalFetchPolicy = this.watchQueryOptions.fetchPolicy;\n\n try {\n if (originalFetchPolicy !== \"no-cache\") {\n observable.resetLastResults();\n observable.silentSetOptions({ fetchPolicy: \"cache-first\" });\n } else {\n observable.silentSetOptions({ fetchPolicy: \"standby\" });\n }\n\n this.subscribeToQuery();\n\n if (originalFetchPolicy === \"no-cache\") {\n return;\n }\n\n observable.resetDiff();\n this.setResult();\n } finally {\n observable.silentSetOptions({ fetchPolicy: originalFetchPolicy });\n }\n }\n\n retain() {\n this.references++;\n clearTimeout(this.autoDisposeTimeoutId);\n let disposed = false;\n\n return () => {\n if (disposed) {\n return;\n }\n\n disposed = true;\n this.references--;\n\n // Wait before fully disposing in case the app is running in strict mode.\n setTimeout(() => {\n if (!this.references) {\n this.dispose();\n }\n });\n };\n }\n\n didChangeOptions(watchQueryOptions: ObservedOptions) {\n return OBSERVED_CHANGED_OPTIONS.some(\n (option) =>\n !equal(this.watchQueryOptions[option], watchQueryOptions[option])\n );\n }\n\n applyOptions(watchQueryOptions: ObservedOptions) {\n const {\n fetchPolicy: currentFetchPolicy,\n canonizeResults: currentCanonizeResults,\n } = this.watchQueryOptions;\n\n // \"standby\" is used when `skip` is set to `true`. Detect when we've\n // enabled the query (i.e. `skip` is `false`) to execute a network request.\n if (\n currentFetchPolicy === \"standby\" &&\n currentFetchPolicy !== watchQueryOptions.fetchPolicy\n ) {\n this.initiateFetch(this.observable.reobserve(watchQueryOptions));\n } else {\n this.observable.silentSetOptions(watchQueryOptions);\n\n if (currentCanonizeResults !== watchQueryOptions.canonizeResults) {\n this.result = { ...this.result, ...this.observable.getCurrentResult() };\n this.promise = createFulfilledPromise(this.result);\n }\n }\n\n return this.promise;\n }\n\n listen(listener: Listener<TData>) {\n this.listeners.add(listener);\n\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n refetch(variables: OperationVariables | undefined) {\n return this.initiateFetch(this.observable.refetch(variables));\n }\n\n fetchMore(options: FetchMoreOptions<TData>) {\n return this.initiateFetch(this.observable.fetchMore<TData>(options));\n }\n\n private dispose() {\n this.subscription.unsubscribe();\n this.onDispose();\n }\n\n private onDispose() {\n // noop. overridable by options\n }\n\n private handleNext(result: ApolloQueryResult<TData>) {\n switch (this.promise.status) {\n case \"pending\": {\n // Maintain the last successful `data` value if the next result does not\n // have one.\n if (result.data === void 0) {\n result.data = this.result.data;\n }\n this.result = result;\n this.resolve?.(result);\n break;\n }\n default: {\n // This occurs when switching to a result that is fully cached when this\n // class is instantiated. ObservableQuery will run reobserve when\n // subscribing, which delivers a result from the cache.\n if (\n result.data === this.result.data &&\n result.networkStatus === this.result.networkStatus\n ) {\n return;\n }\n\n // Maintain the last successful `data` value if the next result does not\n // have one.\n if (result.data === void 0) {\n result.data = this.result.data;\n }\n\n this.result = result;\n this.promise = createFulfilledPromise(result);\n this.deliver(this.promise);\n break;\n }\n }\n }\n\n private handleError(error: ApolloError) {\n this.subscription.unsubscribe();\n this.subscription = this.observable.resubscribeAfterError(\n this.handleNext,\n this.handleError\n );\n\n switch (this.promise.status) {\n case \"pending\": {\n this.reject?.(error);\n break;\n }\n default: {\n this.promise = createRejectedPromise<ApolloQueryResult<TData>>(error);\n this.deliver(this.promise);\n }\n }\n }\n\n private deliver(promise: QueryRefPromise<TData>) {\n this.listeners.forEach((listener) => listener(promise));\n }\n\n private initiateFetch(returnedPromise: Promise<ApolloQueryResult<TData>>) {\n this.promise = this.createPendingPromise();\n this.promise.catch(() => {});\n\n // If the data returned from the fetch is deeply equal to the data already\n // in the cache, `handleNext` will not be triggered leaving the promise we\n // created in a pending state forever. To avoid this situtation, we attempt\n // to resolve the promise if `handleNext` hasn't been run to ensure the\n // promise is resolved correctly.\n returnedPromise\n .then((result) => {\n // In the case of `fetchMore`, this promise is resolved before a cache\n // result is emitted due to the fact that `fetchMore` sets a `no-cache`\n // fetch policy and runs `cache.batch` in its `.then` handler. Because\n // the timing is different, we accidentally run this update twice\n // causing an additional re-render with the `fetchMore` result by\n // itself. By wrapping in `setTimeout`, this should provide a short\n // delay to allow the `QueryInfo.notify` handler to run before this\n // promise is checked.\n // See https://github.com/apollographql/apollo-client/issues/11315 for\n // more information\n setTimeout(() => {\n if (this.promise.status === \"pending\") {\n this.result = result;\n this.resolve?.(result);\n }\n });\n })\n .catch(() => {});\n\n return returnedPromise;\n }\n\n private subscribeToQuery() {\n this.subscription = this.observable\n .filter(\n (result) => !equal(result.data, {}) && !equal(result, this.result)\n )\n .subscribe(this.handleNext, this.handleError);\n }\n\n private setResult() {\n // Don't save this result as last result to prevent delivery of last result\n // when first subscribing\n const result = this.observable.getCurrentResult(false);\n\n if (equal(result, this.result)) {\n return;\n }\n\n this.result = result;\n this.promise =\n (\n result.data &&\n (!result.partial || this.watchQueryOptions.returnPartialData)\n ) ?\n createFulfilledPromise(result)\n : this.createPendingPromise();\n }\n\n private createPendingPromise() {\n return wrapPromiseWithState(\n new Promise<ApolloQueryResult<TData>>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n })\n );\n }\n}\n"]}
@@ -108,7 +108,7 @@ type PreloadQueryOptionsArg<TVariables extends OperationVariables, TOptions = un
108
108
  ];
109
109
  /**
110
110
  * A function that will begin loading a query when called. It's result can be
111
- * read by {@link useReadQuery} which will suspend until the query is loaded.
111
+ * read by `useReadQuery` which will suspend until the query is loaded.
112
112
  * This is useful when you want to start loading a query as early as possible
113
113
  * outside of a React component.
114
114
  *
@@ -134,7 +134,7 @@ type PreloadQueryOptionsArg<TVariables extends OperationVariables, TOptions = un
134
134
  */
135
135
  export interface PreloadQueryFunction {
136
136
  /**
137
- * A function that will begin loading a query when called. It's result can be read by {@link useReadQuery} which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
137
+ * A function that will begin loading a query when called. It's result can be read by `useReadQuery` which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
138
138
  *
139
139
  * @example
140
140
  * ```js
@@ -158,7 +158,7 @@ export interface PreloadQueryFunction {
158
158
  */
159
159
  <TData, TVariables extends OperationVariables, TOptions extends Omit<PreloadQueryOptions, "variables">>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: PreloadQueryOptionsArg<NoInfer<TVariables>, TOptions>): QueryReference<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables>;
160
160
  /**
161
- * A function that will begin loading a query when called. It's result can be read by {@link useReadQuery} which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
161
+ * A function that will begin loading a query when called. It's result can be read by `useReadQuery` which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
162
162
  *
163
163
  * @example
164
164
  * ```js
@@ -185,7 +185,7 @@ export interface PreloadQueryFunction {
185
185
  errorPolicy: "ignore" | "all";
186
186
  }): QueryReference<DeepPartial<TData> | undefined, TVariables>;
187
187
  /**
188
- * A function that will begin loading a query when called. It's result can be read by {@link useReadQuery} which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
188
+ * A function that will begin loading a query when called. It's result can be read by `useReadQuery` which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
189
189
  *
190
190
  * @example
191
191
  * ```js
@@ -211,7 +211,7 @@ export interface PreloadQueryFunction {
211
211
  errorPolicy: "ignore" | "all";
212
212
  }): QueryReference<TData | undefined, TVariables>;
213
213
  /**
214
- * A function that will begin loading a query when called. It's result can be read by {@link useReadQuery} which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
214
+ * A function that will begin loading a query when called. It's result can be read by `useReadQuery` which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
215
215
  *
216
216
  * @example
217
217
  * ```js
@@ -237,7 +237,7 @@ export interface PreloadQueryFunction {
237
237
  returnPartialData: true;
238
238
  }): QueryReference<DeepPartial<TData>, TVariables>;
239
239
  /**
240
- * A function that will begin loading a query when called. It's result can be read by {@link useReadQuery} which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
240
+ * A function that will begin loading a query when called. It's result can be read by `useReadQuery` which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
241
241
  *
242
242
  * @example
243
243
  * ```js
@@ -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;AAsI5E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAyB;IAEzB,OAAO,SAAS,YAAY,CAI1B,KAA0D,EAC1D,OACmD;;QADnD,wBAAA,EAAA,UACgC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAEnD,IAAM,QAAQ,GAAG,IAAI,sBAAsB,CACzC,MAAM,CAAC,UAAU,CAAC,sBACb,OAAO,KACV,KAAK,OAAA,GACyB,CAAC,EACjC;YACE,oBAAoB,EAClB,MAAA,MAAA,MAAM,CAAC,cAAc,CAAC,KAAK,0CAAE,QAAQ,0CAAE,oBAAoB;SAC9D,CACF,CAAC;QAEF,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,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 { QueryReference } from \"../internal/index.js\";\nimport type { NoInfer } from \"../index.js\";\n\ntype VariablesOption<TVariables extends OperationVariables> =\n [TVariables] extends [never] ?\n {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#variables:member} */\n variables?: Record<string, never>;\n }\n : {} extends OnlyRequiredProperties<TVariables> ?\n {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#variables:member} */\n variables?: TVariables;\n }\n : {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#variables:member} */\n variables: TVariables;\n };\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 {@link 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 ): QueryReference<\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 ): QueryReference<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 ): QueryReference<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 ): QueryReference<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 ): QueryReference<TData, TVariables>;\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 * @alpha\n */\nexport function createQueryPreloader(\n client: ApolloClient<any>\n): PreloadQueryFunction {\n return 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 ): QueryReference<TData, TVariables> {\n const queryRef = 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 return wrapQueryRef(queryRef);\n };\n}\n"]}
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;AAsI5E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAyB;IAEzB,OAAO,SAAS,YAAY,CAI1B,KAA0D,EAC1D,OACmD;;QADnD,wBAAA,EAAA,UACgC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAEnD,IAAM,QAAQ,GAAG,IAAI,sBAAsB,CACzC,MAAM,CAAC,UAAU,CAAC,sBACb,OAAO,KACV,KAAK,OAAA,GACyB,CAAC,EACjC;YACE,oBAAoB,EAClB,MAAA,MAAA,MAAM,CAAC,cAAc,CAAC,KAAK,0CAAE,QAAQ,0CAAE,oBAAoB;SAC9D,CACF,CAAC;QAEF,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,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 { QueryReference } from \"../internal/index.js\";\nimport type { NoInfer } from \"../index.js\";\n\ntype VariablesOption<TVariables extends OperationVariables> =\n [TVariables] extends [never] ?\n {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#variables:member} */\n variables?: Record<string, never>;\n }\n : {} extends OnlyRequiredProperties<TVariables> ?\n {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#variables:member} */\n variables?: TVariables;\n }\n : {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#variables:member} */\n variables: TVariables;\n };\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 ): QueryReference<\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 ): QueryReference<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 ): QueryReference<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 ): QueryReference<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 ): QueryReference<TData, TVariables>;\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 * @alpha\n */\nexport function createQueryPreloader(\n client: ApolloClient<any>\n): PreloadQueryFunction {\n return 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 ): QueryReference<TData, TVariables> {\n const queryRef = 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 return wrapQueryRef(queryRef);\n };\n}\n"]}
@@ -21,7 +21,7 @@ export interface BaseQueryOptions<TVariables extends OperationVariables = Operat
21
21
  */
22
22
  ssr?: boolean;
23
23
  /**
24
- * The instance of {@link ApolloClient} to use to execute the query.
24
+ * The instance of `ApolloClient` to use to execute the query.
25
25
  *
26
26
  * By default, the instance that's passed down via context is used, but you can provide a different instance here.
27
27
  *
@@ -266,7 +266,7 @@ export interface LazyQueryHookExecOptions<TData = any, TVariables extends Operat
266
266
  export type SuspenseQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
267
267
  export interface SuspenseQueryHookOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
268
268
  /**
269
- * The instance of {@link ApolloClient} to use to execute the query.
269
+ * The instance of `ApolloClient` to use to execute the query.
270
270
  *
271
271
  * By default, the instance that's passed down via context is used, but you can provide a different instance here.
272
272
  *
@@ -416,7 +416,7 @@ export interface LoadableQueryHookOptions {
416
416
  */
417
417
  canonizeResults?: boolean;
418
418
  /**
419
- * The instance of {@link ApolloClient} to use to execute the query.
419
+ * The instance of `ApolloClient` to use to execute the query.
420
420
  *
421
421
  * By default, the instance that's passed down via context is used, but you can provide a different instance here.
422
422
  *
@@ -40,7 +40,7 @@ export interface QueryOptionsDocumentation {
40
40
  */
41
41
  fetchPolicy: unknown;
42
42
  /**
43
- * Specifies the {@link FetchPolicy} to be used after this query has completed.
43
+ * Specifies the `FetchPolicy` to be used after this query has completed.
44
44
  *
45
45
  * @docGroup 3. Caching options
46
46
  */
@@ -151,7 +151,7 @@ export interface QueryOptionsDocumentation {
151
151
  */
152
152
  onError: unknown;
153
153
  /**
154
- * The instance of {@link ApolloClient} to use to execute the query.
154
+ * The instance of `ApolloClient` to use to execute the query.
155
155
  *
156
156
  * By default, the instance that's passed down via context is used, but you
157
157
  * can provide a different instance here.
@@ -340,7 +340,7 @@ export interface MutationOptionsDocumentation {
340
340
  */
341
341
  optimisticResponse: unknown;
342
342
  /**
343
- * A {@link MutationQueryReducersMap}, which is map from query names to
343
+ * A `MutationQueryReducersMap`, which is map from query names to
344
344
  * mutation query reducers. Briefly, this map defines how to incorporate the
345
345
  * results of the mutation into the results of queries that are currently
346
346
  * being watched by your application.
@@ -488,7 +488,7 @@ export interface SubscriptionOptionsDocumentation {
488
488
  */
489
489
  variables: unknown;
490
490
  /**
491
- * Specifies the {@link ErrorPolicy} to be used for this operation
491
+ * Specifies the `ErrorPolicy` to be used for this operation
492
492
  */
493
493
  errorPolicy: unknown;
494
494
  /**