graphql-constraint-directive icon indicating copy to clipboard operation
graphql-constraint-directive copied to clipboard

ConstraintDirectiveError typescript definition

Open MiroslavPetrik opened this issue 3 years ago • 1 comments

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

MiroslavPetrik avatar Aug 09 '22 20:08 MiroslavPetrik

Apologies for the delay @MiroslavPetrik. Happy to accept a PR to update the type script definitions

confuser avatar Sep 05 '22 20:09 confuser