UNPKG

1.63 kBJavaScriptView Raw
1import { __assign } from "tslib";
2import { InternalQueryReference, wrapQueryRef } from "../internal/index.js";
3import { wrapHook } from "../hooks/internal/index.js";
4/**
5 * A higher order function that returns a `preloadQuery` function which
6 * can be used to begin loading a query with the given `client`. This is useful
7 * when you want to start loading a query as early as possible outside of a
8 * React component.
9 *
10 * > 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.
11 *
12 * @param client - The `ApolloClient` instance that will be used to load queries
13 * from the returned `preloadQuery` function.
14 * @returns The `preloadQuery` function.
15 *
16 * @example
17 * ```js
18 * const preloadQuery = createQueryPreloader(client);
19 * ```
20 * @since 3.9.0
21 */
22export function createQueryPreloader(client) {
23 return wrapHook("createQueryPreloader", _createQueryPreloader, client)(client);
24}
25var _createQueryPreloader = function (client) {
26 return function preloadQuery(query, options) {
27 var _a, _b;
28 if (options === void 0) { options = Object.create(null); }
29 var queryRef = new InternalQueryReference(client.watchQuery(__assign(__assign({}, options), { query: query })), {
30 autoDisposeTimeoutMs: (_b = (_a = client.defaultOptions.react) === null || _a === void 0 ? void 0 : _a.suspense) === null || _b === void 0 ? void 0 : _b.autoDisposeTimeoutMs,
31 });
32 return wrapQueryRef(queryRef);
33 };
34};
35//# sourceMappingURL=createQueryPreloader.js.map
\No newline at end of file