"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createGraphiQLFetcher = void 0; var lib_1 = require("./lib"); function createGraphiQLFetcher(options) { var httpFetch; if (typeof window !== 'undefined' && window.fetch) { httpFetch = window.fetch; } if ((options === null || options === void 0 ? void 0 : options.enableIncrementalDelivery) === null || options.enableIncrementalDelivery !== false) { options.enableIncrementalDelivery = true; } if (options.fetch) { httpFetch = options.fetch; } if (!httpFetch) { throw new Error('No valid fetcher implementation available'); } var simpleFetcher = (0, lib_1.createSimpleFetcher)(options, httpFetch); var httpFetcher = options.enableIncrementalDelivery ? (0, lib_1.createMultipartFetcher)(options, httpFetch) : simpleFetcher; return function (graphQLParams, fetcherOpts) { if (graphQLParams.operationName === 'IntrospectionQuery') { return (options.schemaFetcher || simpleFetcher)(graphQLParams, fetcherOpts); } var isSubscription = (fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.documentAST) ? (0, lib_1.isSubscriptionWithName)(fetcherOpts.documentAST, graphQLParams.operationName || undefined) : false; if (isSubscription) { var wsFetcher = (0, lib_1.getWsFetcher)(options, fetcherOpts); if (!wsFetcher) { throw new Error("Your GraphiQL createFetcher is not properly configured for websocket subscriptions yet. ".concat(options.subscriptionUrl ? "Provided URL ".concat(options.subscriptionUrl, " failed") : 'Please provide subscriptionUrl, wsClient or legacyClient option first.')); } return wsFetcher(graphQLParams); } return httpFetcher(graphQLParams, fetcherOpts); }; } exports.createGraphiQLFetcher = createGraphiQLFetcher; //# sourceMappingURL=createFetcher.js.map