Skip to content

Generated schemas are missing default values in case of array input fields with default values #1361

@AndKiel

Description

@AndKiel

The problem (current behaviour)

When a GraphQL schema includes input fields accepting arrays with default values, such as:

  someField: [String!]! = []

Then the generated TypeScript code will include an invalid line:

    someField: z.array(z.string()),

resulting in the schema rejecting undefined value during parsing. The GraphQL API request would still work when the input object is sent without such a property (lacks a value).

Expected behaviour

When generating schemas, such fields should either be generated with a default value or made optional, or both:

    someField: z.array(z.string()).default([]),
    someField: z.array(z.string()).optional(),
    someField: z.array(z.string()).default([]).optional(),

I've seen it for String, enum and object (another input type) arrays.

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