Skip to content

bug: falsy directive args are dropped #184

Closed
@elijaholmos

Description

@elijaholmos

When supplying a falsy argument to a custom directive, the argument is omitted from the generated schema.

Sample GQL: (with codgen config from https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema/blob/main/codegen.yml)

input EventArgumentInput {
  name: String! @constraint(minLength: 0)
  value: String! @constraint(startsWith: "foo")
}

directive @constraint(
  minLength: Int
  startsWith: String
) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION

Expected Schema Output:

export function EventArgumentInputSchema(): yup.SchemaOf<EventArgumentInput> {
  return yup.object({
    name: yup.string().defined().min(0),
    value: yup.string().defined().matches(/^foo/)
  })
}

Actual Schema Output:

export function EventArgumentInputSchema(): yup.SchemaOf<EventArgumentInput> {
  return yup.object({
    name: yup.string().defined().min(), // <-- "Expected 1-2 arguments, but got 0. ts(2554)"
    value: yup.string().defined().matches(/^foo/)
  })
}

I intend on submitting a PR to resolve this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions