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

Expose validate functions #171

Open
jcoc611-gvt opened this issue May 7, 2023 · 1 comment
Open

Expose validate functions #171

jcoc611-gvt opened this issue May 7, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@jcoc611-gvt
Copy link
Contributor

jcoc611-gvt commented May 7, 2023

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)
}
@confuser
Copy link
Owner

PR welcome

@confuser confuser added the enhancement New feature or request label May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants