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

Custom validation directives for arguments and input fields #1215

Open
korsNaike opened this issue Jan 27, 2025 · 0 comments
Open

Custom validation directives for arguments and input fields #1215

korsNaike opened this issue Jan 27, 2025 · 0 comments

Comments

@korsNaike
Copy link

The essence of the problem: I wanted to implement a custom directive to check a string for matching a regular expression, for example:

input ChangePasswordInput {
    password: String @regex(pattern: "^(?=.*[A-ZА-Я])(?=.*[a-zа-я])(?=.*[0-9])(?=.*\\W).{8,}$", errorMessage: "Bad Request")
}

But I can't do this, no matter how hard I try, I tried to substitute the parse_value and parse_literal methods for the object in the "type" field of "GraphQLInputField", but this substitution will also affect the change in all other fields that use the same data type. Then I tried to make a copy of the object from the type field: "field.type = deepcopy(field.type)", but it didn't help, validation just stopped working. In this case, it would be convenient to have a field for the "GraphQLInputField" and "GraphQLArgument" classes to set a callback that would be called when receiving data to this input.
Such functionality would be useful for "INPUT_FIELD_DEFINITION" and for "ARGUMENT_DEFINITION".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant