Skip to content

Validation

SamGodwin2 edited this page Aug 3, 2018 · 19 revisions

This document describes the overall technical design for the implementation of Validation within EQ Author.

GraphQL schema

Validation requires new types, queries and mutations to be added into Author's GraphQL schema.

# Proposed changes to GraphQL schema to support validation.

union ValidationType = NumberValidation | DateValidation | DateRangeValidation

type NumberValidation {
  minValue: MinValueValidationRule!
  maxValue: MaxValueValidationRule!
}

type DateValidation {
  earliestDate: EarliestDateValidationRule!
  latestDate: LatestDateValidationRule!
}

type DateRangeValidation {
  earliestDate: EarliestDateValidationRule!
  latestDate: LatestDateValidationRule!
  minDuration: MinDurationValidationRule!
  maxDuration: MaxDurationValidationRule!
}

enum RelativePosition {
  Before
  After
}

interface ValidationRule {
  id: ID!
  enabled: Boolean!
}

type MinValueValidationRule implements ValidationRule {
  id: ID!
  enabled: Boolean!
  inclusive: Boolean!
  custom: Int
}

type MaxValueValidationRule implements ValidationRule {
  id: ID!
  enabled: Boolean!
  inclusive: Boolean!
  custom: Int
  # previousAnswer: BasicAnswer
  # metadata: Metadata
}

type EarliestDateValidationRule implements ValidationRule {
  id: ID!
  enabled: Boolean!
  offset: Duration!
  relativePostion: RelativePosition!
  today: Boolean!
  custom: Date
  # previousAnswer: BasicAnswer
  # metadata: Metadata
}

type LatestDateValidationRule implements ValidationRule {
  id: ID!
  enabled: Boolean!
  offset: Duration!
  relativePostion: RelativePosition!
  today: Boolean!
  custom: Date
  # previousAnswer: BasicAnswer
  # metadata: Metadata
}

type MinDurationValidationRule implements ValidationRule {
  id: ID!
  enabled: Boolean!
  custom: Duration
}

type MaxDurationValidationRule implements ValidationRule {
 id: ID!
 enabled: Boolean!
 custom: Duration
}

type Duration {
  days: Int
}

# type Duration {
#    value: Int
#    unit: DurationUnit!
# }

enum DurationUnit {
  Days
}


# Mutations

Mutations {
    toggleValidationRule(input: ToggleValidationRuleInput!): ValidationRule!
    updateValidationRule(input: UpdateValidationRuleInput!): ValidationRule!
}

input ToggleValidationRuleInput {
  validationRuleId: ID!
  enabled: Boolean!
}


input UpdateValidationRuleInput {
  answerId: ID!
  validationRuleId: ID!
  minValueInput:  UpdateMinValueInput
  maxValueInput: UpdateMaxValueInput
  earliestDateInput: UpdateEarliestDateInput
  latestDateInput: UpdateLatestDateInput
  minDurationInput: UpdateMinDurationInput
  maxDurationInput: UpdateMaxDurationInput
}

input UpdateMinValueInput {
  inclusive: Boolean
  custom: Int
}

input UpdateMaxValueInput {
    inclusive: Boolean
    custom: Int
    # previousAnswer: ID
    # metadata: ID
}

input UpdateEarliestDateInput {
    duration: DurationInput
    today: Boolean
    custom: Date
    # previousAnswer: ID
    # metadata: ID
}

input UpdateLatestDateInput {
    duration: DurationInput
    today: Boolean
    custom: Date
    # previousAnswer: ID
    # metadata: ID
}

input UpdateMinDurationInput {
    duration: DurationInput
}

input UpdateMaxDurationInput {
    duration: DurationInput
}

input DurationInput {
    value: Int
    unit: DurationUnit!
}

Database schema changes

New tables are required in order to support validation within Author.

Entity diagram of validation schema

validations

Validation entities group one or more validation rules. e.g. NumberAnswerValidation or DateRangeValidation

e.g.

id name description
1 Number Validation for numeric answers
2 Date

validation_rules

Specific validation rules e.g. MinValueValidationRule or EarliestDateValidationRule

id name validation_id
1 Min value 1
2 Max value 1

answer_type_validations

This entity establishes a relationship between specific answer types and the validation (group of validation rules).

e.g.

id answer_type validation_id
1 Number 1
2 Currency 1
3 DateRange 1

answer_validation_rules

This overrides default validation rule configuration for specific answer instances.

e.g.

id answer_id validation_rule_id enabled config
1 1 1 true { inclusive: true }

validation_reference_value

Stores reference values for specific instances of validation rules.

e.g.

id prev_answer_id metadata_id custom_value answer_validation_rule_id
1 null null "100" 1
Clone this wiki locally