graphql-compose-mongoose
Version:
Plugin for `graphql-compose` which derive a graphql types from a mongoose model.
51 lines • 1.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidationError = void 0;
exports.getValidatorErrorOTC = getValidatorErrorOTC;
exports.getValidationErrorOTC = getValidationErrorOTC;
class ValidationError extends Error {
constructor(validation) {
super(validation.message);
this.errors = validation.errors;
this.__proto__ = ValidationError.prototype;
}
}
exports.ValidationError = ValidationError;
function getValidatorErrorOTC(schemaComposer) {
return schemaComposer.getOrCreateOTC('ValidatorError', (otc) => {
otc.addFields({
message: {
description: 'Validation error message',
type: 'String',
},
path: {
description: 'Source of the validation error from the model path',
type: 'String',
},
value: {
description: 'Field value which occurs the validation error',
type: 'JSON',
},
idx: {
description: 'Input record idx in array which occurs the validation error. This `idx` is useful for createMany operation. For singular operations it always be 0. For *Many operations `idx` represents record index in array received from user.',
type: 'Int!',
resolve: (s) => s.idx || 0,
},
});
});
}
function getValidationErrorOTC(schemaComposer) {
return schemaComposer.getOrCreateOTC('ValidationError', (otc) => {
otc.addFields({
message: {
description: 'Combined error message from all validators',
type: 'String',
},
errors: {
description: 'List of validator errors',
type: getValidatorErrorOTC(schemaComposer).NonNull.List,
},
});
});
}
//# sourceMappingURL=ValidationError.js.map