Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstraintDirectiveError typescript definition #101

Open
MiroslavPetrik opened this issue Aug 9, 2022 · 1 comment
Open

ConstraintDirectiveError typescript definition #101

MiroslavPetrik opened this issue Aug 9, 2022 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@MiroslavPetrik
Copy link

MiroslavPetrik commented Aug 9, 2022

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

@confuser
Copy link
Owner

confuser commented Sep 5, 2022

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

@confuser confuser added enhancement New feature or request good first issue Good for newcomers labels Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants