"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSSRQuery = void 0;
const react_1 = require("@apollo/client/react");
const useSSRQuery = function (query, options = {}) {
    function notAllowed() {
        throw new Error("This method cannot be called during SSR.");
    }
    const client = (0, react_1.useApolloClient)(options.client);
    const baseResult = {
        client,
        refetch: notAllowed,
        fetchMore: notAllowed,
        subscribeToMore: notAllowed,
        updateQuery: notAllowed,
        startPolling: notAllowed,
        stopPolling: notAllowed,
        variables: options?.variables,
        previousData: undefined,
    };
    if (options.skip) {
        return withoutObservableAccess({
            ...baseResult,
            ...react_1.useQuery.skipStandbyResult,
        });
    }
    if (options.ssr === false) {
        return withoutObservableAccess({
            ...baseResult,
            ...react_1.useQuery.ssrDisabledResult,
        });
    }
    let observable = this.getObservableQuery(query, options.variables);
    if (!observable) {
        observable = client.watchQuery({
            query,
            ...options,
            fetchPolicy: (options.fetchPolicy === "network-only" ||
                options.fetchPolicy === "cache-and-network") ?
                "cache-first"
                : options.fetchPolicy,
        });
        this.onCreatedObservableQuery(observable, query, options.variables);
    }
    return {
        observable,
        ...observable.getCurrentResult(),
        ...baseResult,
    };
};
exports.useSSRQuery = useSSRQuery;
function withoutObservableAccess(value) {
    Object.defineProperty(value, "observable", {
        get() {
            throw new Error('"observable" property is not accessible on skipped hooks or hook calls with `ssr: false` during SSR');
        },
    });
    return value;
}
//# sourceMappingURL=useSSRQuery.cjs.map
