@apollo/core-schema
Version:
Apollo Core Schema processing library
42 lines • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.err = exports.GraphQLErrorExt = void 0;
const graphql_1 = require("graphql");
class GraphQLErrorExt extends graphql_1.GraphQLError {
constructor(code, message, props) {
super(message, props);
this.code = code;
if (props)
for (const prop in props)
if (!GraphQLErrorExt.BASE_PROPS.has(prop)) {
this[prop] = props[prop];
}
this.name = code;
this.extensions.code = code;
}
throw() { throw this; }
toString() {
let output = `[${this.code}] ${super.toString()}`;
const causes = this.causes;
if (causes && causes.length) {
output += "\ncaused by:";
for (const cause of this.causes || []) {
if (!cause)
continue;
output += "\n\n - ";
output += cause.toString().split("\n").join("\n ");
}
}
return output;
}
}
exports.GraphQLErrorExt = GraphQLErrorExt;
GraphQLErrorExt.BASE_PROPS = new Set("nodes source positions path originalError extensions".split(" "));
function err(code, props) {
const message = typeof props === "string" ? props : props.message;
const error = new GraphQLErrorExt(code, message, typeof props === "string" ? undefined : props);
return error;
}
exports.err = err;
exports.default = err;
//# sourceMappingURL=error.js.map