Skip to content

How to handle enum on directive arguments? #611

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

Closed
azu opened this issue Apr 7, 2024 · 4 comments · Fixed by #612
Closed

How to handle enum on directive arguments? #611

azu opened this issue Apr 7, 2024 · 4 comments · Fixed by #612

Comments

@azu
Copy link

azu commented Apr 7, 2024

I want to handle Enum value on directive arguments.

For example, @validateString(format: EMAIL) use enum value on arguemnts.

directive @validateString(
    format: StringFormat
) on INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION

enum StringFormat {
    EMAIL
    IP
}

# All validation directives
input Example {
    email: String! @validateString(format: EMAIL)
    ip: String! @validateString(format: IP)
}

graphql-codegen-typescript-validation-schema always ignore the enum value, I think.

How to handle enum on directive arguments?

Example

I try to write following config, but it is just ignored.

        "src/graphql.ts": {
            plugins: [
                "typescript",
                "typescript-validation-schema"
            ],
            config: {
                schema: "zod",
                strictScalars: true,
                scalars: {
                    ID: "string"
                },
                scalarSchemas: {

                },
                enumsAsTypes: true,
                directives: {
                    validateString: {
                        format: {
                            EMAIL: "email",
                            IP: "ip"
                        }
                    }
                },
            },
        }

It is ideal to be able to convert to the next by setting something.

@validateString(format: EMAIL)

z.string().email()
@Code-Hex
Copy link
Owner

Code-Hex commented Apr 7, 2024

@azu Thanks for asking question to me!

I apologize for not mentioning this in the documentation. As an implementation, the directive argument currently supports only pure String.

I think it is probably better to accept any type that can be converted to a String. I will add this feature.

@Code-Hex
Copy link
Owner

Code-Hex commented Apr 7, 2024

In addition, this example (email: email) meant [directive-args-string]: validation-schema-name.

format:
  email: email

@Code-Hex
Copy link
Owner

Code-Hex commented Apr 7, 2024

@azu I supported enum in 0.14.1. Could you try this one? Thanks!

@azu
Copy link
Author

azu commented Apr 7, 2024

@Code-Hex Thanks!

I've confirmed to work Enum.
azu/graphql-codegen-typescript-validation-schema-enum-as-param@e3d1d70

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