"use strict";
/**
 * GQTY: You can safely modify this file and Query Fetcher based on your needs
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.track = exports.refetch = exports.resolved = exports.subscription = exports.mutate = exports.mutation = exports.query = exports.client = void 0;
const subscriptions_1 = require("@gqty/subscriptions");
const gqty_1 = require("gqty");
const schema_generated_1 = require("./schema.generated");
const queryFetcher = async (query, variables, fetchOptions) => {
    // Modify "/api/graphql" if needed
    const response = await fetch('/api/graphql', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            query,
            variables,
        }),
        mode: 'cors',
        ...fetchOptions,
    });
    const json = await response.json();
    return json;
};
const subscriptionsClient = typeof window !== 'undefined'
    ? (0, subscriptions_1.createSubscriptionsClient)({
        wsEndpoint: () => {
            // Modify if needed
            const url = new URL('/api/graphql', window.location.href);
            url.protocol = url.protocol.replace('http', 'ws');
            return url.href;
        },
    })
    : undefined;
exports.client = (0, gqty_1.createClient)({
    schema: schema_generated_1.generatedSchema,
    scalarsEnumsHash: schema_generated_1.scalarsEnumsHash,
    queryFetcher,
    subscriptionsClient,
});
const { query, mutation, mutate, subscription, resolved, refetch, track } = exports.client;
exports.query = query;
exports.mutation = mutation;
exports.mutate = mutate;
exports.subscription = subscription;
exports.resolved = resolved;
exports.refetch = refetch;
exports.track = track;
__exportStar(require("./schema.generated"), exports);
