"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CombinedGraphQLErrors = void 0;
const utilities_1 = require("@apollo/client/utilities");
/**
 * Represents the combined list of GraphQL errors returned from the server in a
 * GraphQL response.
 */
class CombinedGraphQLErrors extends Error {
    /**
     * The raw list of GraphQL errors returned in a GraphQL response.
     */
    errors;
    /**
     * Partial data returned in the GraphQL response.
     */
    data;
    constructor(result) {
        const errors = (0, utilities_1.getGraphQLErrorsFromResult)(result);
        super(formatMessage(errors));
        this.errors = errors;
        this.data = result.data;
        this.name = "CombinedGraphQLErrors";
        Object.setPrototypeOf(this, CombinedGraphQLErrors.prototype);
    }
}
exports.CombinedGraphQLErrors = CombinedGraphQLErrors;
function formatMessage(errors) {
    const messageList = errors
        // Handle non-spec-compliant servers: See #1185
        .filter((e) => e)
        .map((e) => `- ${e.message}`)
        .join("\n");
    return `The GraphQL server returned with errors:
${messageList}`;
}
//# sourceMappingURL=CombinedGraphQLErrors.cjs.map
