This repository was archived by the owner on Dec 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
This repository was archived by the owner on Dec 25, 2025. It is now read-only.
[FEATURE] Validation (directive) #36
Copy link
Copy link
Closed
Description
Currently, fabrix does not support any form of validation, but for a long run, fabrix is going to support graphql-constraint-spec that for future.
In addition to that, client-side validation is clearly also needed in some cases, so as an initial approach, add field-level validation with directives.
Design
Fabrix provides the new input types for constraints as follows. These fields come partially from graphql-constraint-directive which is an implementation of the spec.
input FabrixFormConstraint {
"""
String
"""
minLength: Int
maxLength: Int
pattern: String
format: String
oneOf: [String]
"""
Int
"""
min: Int
max: Int
exclusiveMin: Int
exclusiveMax: Int
multipleOf: Int
oneOf: [Int]
"""
Float
"""
min: Float
max: Float
exclusiveMin: Float
exclusiveMax: Float
multipleOf: Float
oneOf: [Float]
}Discussion points
The spec, graphql-constraint-spec has not been updated since 7 years ago. I don't have to follow everything with the thing that is way too stale, so need some discussion to decide our own do's and dont's.
- Availability of some rules
startsWith,endsWith,contains,notContains: these can be replaced withpatternas well, but error messages of them could be more intuitive to users thanpattern. Also, when it comes to customizing error messages with i18n, usingpatterndoes not have enough controllability.equals:patterncan work out for string values as well here. As for Int/Float values, I think that's pretty rare to check if the value has the exact match with the other value as validation.
- Types for
format: currently, fabrix internally uses Ajv to implement validator, so the idea for now is just using ajv-formats. It has variety of common string formats, so it looks enough. - The ways to handle conditional validation and field reference.
Usage
mutation createUser($input: CreateUserInput!) {
createUser(input: $input)
@fabrixForm(
input: [
{ field: "name", constraint: { maxLength: 50 } },
{ field: "email", constraint: { format: "email" } },
]
) {
id
}
}Metadata
Metadata
Assignees
Labels
featureNew feature or requestNew feature or request
Type
Projects
Status
Done