Code-Hex/graphql-codegen-typescript-validation-schema

How to handle enum on directive arguments?

azu opened this issue · 4 comments

azu commented

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()

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

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

format:
  email: email

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