"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.initialiseClient = exports.responseMiddleware = void 0;
const graphql_request_1 = require("graphql-request");
const lodash_1 = require("lodash");
const errors_1 = require("./errors");
const responseMiddleware = (response) => {
    if (response instanceof errors_1.HealthieError) {
        return;
    }
    const errors = (0, errors_1.getHealthieErrorFromResponse)(response);
    if (!(0, lodash_1.isNil)(errors) && errors.length > 0) {
        throw new errors_1.HealthieError(errors);
    }
};
exports.responseMiddleware = responseMiddleware;
/**
 * @deprecated DO NOT USE
 * DO NOT USE
 */
const initialiseClient = (s) => {
    const { apiUrl, apiKey } = s;
    if (apiUrl !== undefined && apiKey !== undefined) {
        return new graphql_request_1.GraphQLClient(apiUrl, {
            headers: {
                AuthorizationSource: 'API',
                Authorization: `Basic ${apiKey}`,
            },
            responseMiddleware: exports.responseMiddleware,
        });
    }
    return undefined;
};
exports.initialiseClient = initialiseClient;
//# sourceMappingURL=graphqlClient.js.map