import { __assign, __rest, __spreadArray } from "tslib";
import { canonicalStringify } from "../../utilities/index.js";
import { wrapQueryRef } from "../cache/QueryReference.js";
import { getSuspenseCache } from "../cache/index.js";
export function createQueryPreloader(client) {
    var suspenseCache = getSuspenseCache(client);
    function preloadQuery(query, options) {
        if (options === void 0) { options = Object.create(null); }
        var variables = options.variables, _a = options.queryKey, queryKey = _a === void 0 ? [] : _a, watchQueryOptions = __rest(options, ["variables", "queryKey"]);
        var cacheKey = __spreadArray([
            query,
            canonicalStringify(variables)
        ], [].concat(queryKey), true);
        var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
            return client.watchQuery(__assign({ query: query, variables: variables }, watchQueryOptions));
        });
        return wrapQueryRef(queryRef);
    }
    return preloadQuery;
}
//# sourceMappingURL=createQueryPreloader.js.map