Skip to content

Custom validation directives for arguments and input fields #1215

Open
@korsNaike

Description

@korsNaike

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions