graphql-constraint-directive
graphql-constraint-directive copied to clipboard
ConstraintDirectiveError typescript definition
I have a use case where I have to translate the error message, so I have to go over the error structure and map it.
Here is my partial type I'm currently using
type StringConstraint<T extends string, V = string> = {
arg: T
value: V
}
type NumberConstraint<T extends string> = {
arg: T
value: number
}
type ConstraintDirectiveError = {
code: 'ERR_GRAPHQL_CONSTRAINT_VALIDATION'
fieldName: string
context: (
| StringConstraint<'minLength'>
| StringConstraint<'maxLength'>
| StringConstraint<'format', 'email'>
| NumberConstraint<'min'>
| NumberConstraint<'max'>
)[] // TODO: rest of constrains
}
I would be handy to have it (or something similar) in the library, so I can easily define a translations for the constrains
Apologies for the delay @MiroslavPetrik. Happy to accept a PR to update the type script definitions