confuser/graphql-constraint-directive

Expose validate functions

jcoc611-gvt opened this issue · 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)
}

PR welcome