import { getGraphQLErrorsFromResult } from "@apollo/client/utilities";
/**
 * Represents the combined list of GraphQL errors returned from the server in a
 * GraphQL response.
 */
export 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 = getGraphQLErrorsFromResult(result);
        super(formatMessage(errors));
        this.errors = errors;
        this.data = result.data;
        this.name = "CombinedGraphQLErrors";
        Object.setPrototypeOf(this, CombinedGraphQLErrors.prototype);
    }
}
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.js.map
