import { brand, isBranded } from "./utils.js";
function defaultFormatMessage(errors) {
    return (errors
        // Handle non-spec-compliant servers: See #1185
        .filter((e) => e)
        .map((e) => e.message || "Error message not found.")
        .join("\n"));
}
/**
 * Represents the combined list of GraphQL errors returned from the server in a
 * GraphQL response.
 */
export class CombinedGraphQLErrors extends Error {
    /** Determine if an error is a `CombinedGraphQLErrors` instance */
    static is(error) {
        return isBranded(error, "CombinedGraphQLErrors");
    }
    /**
     * Formats the error message used for the error `message` property. Override
     * to provide your own formatting.
     */
    static formatMessage = defaultFormatMessage;
    /**
     * The raw list of GraphQL errors returned in a GraphQL response.
     */
    errors;
    /**
     * Partial data returned in the GraphQL response.
     */
    data;
    /**
     * Extensions added to the result.
     */
    extensions;
    constructor(result, errors = result.errors || []) {
        super(CombinedGraphQLErrors.formatMessage(errors, {
            result,
            defaultFormatMessage,
        }));
        this.errors = errors;
        this.data = result.data;
        this.extensions = result.extensions;
        this.name = "CombinedGraphQLErrors";
        brand(this);
        Object.setPrototypeOf(this, CombinedGraphQLErrors.prototype);
    }
}
//# sourceMappingURL=CombinedGraphQLErrors.js.map
