diff --git a/eq-author-api/schema/resolvers/base.js b/eq-author-api/schema/resolvers/base.js index e694571a53..1f39b72d57 100644 --- a/eq-author-api/schema/resolvers/base.js +++ b/eq-author-api/schema/resolvers/base.js @@ -79,6 +79,7 @@ const { getAnswerByOptionId, setDataVersion, authorisedRequest, + returnAllValidationErrors, } = require("./utils"); const createAnswer = require("../../src/businessLogic/createAnswer"); @@ -1721,6 +1722,10 @@ const Resolvers = { }, validationErrorInfo: ({ id }, _, ctx) => returnValidationErrors(ctx, id, ({ type }) => type === "root"), + + allValidationErrorInfo: ({ id }, _, ctx) => + returnAllValidationErrors(ctx, id), + totalErrorCount: (questionnaire, args, ctx) => { return ctx.validationErrorInfo.length; }, diff --git a/eq-author-api/schema/resolvers/utils/validation.js b/eq-author-api/schema/resolvers/utils/validation.js index 07c1b47bc7..d264658f0d 100644 --- a/eq-author-api/schema/resolvers/utils/validation.js +++ b/eq-author-api/schema/resolvers/utils/validation.js @@ -45,8 +45,27 @@ const returnValidationErrors = (ctx, id, ...conditions) => { }; }; +const returnAllValidationErrors = (ctx, id) => { + const errors = getValidationErrorInfo(ctx); + + if (!errors.length) { + return { + id, + errors: [], + totalCount: 0, + }; + } + + return { + id, + errors, + totalCount: errors.length, + }; +}; + module.exports = { getValidationById, getValidationErrorInfo, returnValidationErrors, + returnAllValidationErrors, }; diff --git a/eq-author-api/schema/typeDefs.js b/eq-author-api/schema/typeDefs.js index c73165f42e..8a98d32ff7 100644 --- a/eq-author-api/schema/typeDefs.js +++ b/eq-author-api/schema/typeDefs.js @@ -92,6 +92,7 @@ type Questionnaire { locked: Boolean publishHistory: [PublishHistoryEvent] validationErrorInfo: ValidationErrorInfo + allValidationErrorInfo: AllValidationErrorInfo submission: Submission supplementaryData: SupplementaryData } @@ -487,12 +488,25 @@ type ValidationError { errorCode: String! } +type AllValidationError { + id: String! + type: String! + field: String! + errorCode: String! + pageId: String +} + type ValidationErrorInfo { id: ID! errors: [ValidationError!]! totalCount: Int! } +type AllValidationErrorInfo { + id: ID! + errors: [AllValidationError!]! + totalCount: Int! +} union ValidationType = NumberValidation | DateValidation | DateRangeValidation