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

Expose validate functions

Open jcoc611-gvt opened this issue 2 years ago • 1 comments

Hi there! Thanks for the awesome package!

Would you be willing to expose the validate functions in scalars/number.js and scalars/string.js? I would like to be able to manually validate fields on the client side without having to construct a GraphQL mutation.

I can probably make a PR if you are interested!

The scenario is being able to reuse these constraint directives to also validate things like HTML forms (which would not necessarily use GraphQL, but would logically still be the same types).

More context if you are interested: I'm writing a codegen plugin for @graphql-codegen/cli which takes in a declaration such as:

type User {
  email: String! @constraint(format: "email")
}

and produces:

import { validateString } from 'graphql-constraint-directive'; // this part missing
export const UserValidator = {
  email: (value: string) => validateString('email', {format: "email"}, value)
}

jcoc611-gvt avatar May 07 '23 16:05 jcoc611-gvt

PR welcome

confuser avatar May 19 '23 08:05 confuser