Skip to content

Invalid TypeScript code generated for String fields having default value with line breaks #687

Closed
@AndKiel

Description

@AndKiel

The problem (current behaviour)

When graphQL schema includes String fields having default values with line breaks such as:

  someField: String = "Some\nThing"

then the generated TypeScript code will include an invalid line:

    someField: z.string().default("Some
Thing").nullish(),

resulting in the following compilation error:

error TS1002: Unterminated string literal.

Expected behaviour

When generating default values, strings should be sanitized and used exactly as they are in the input schema, resulting in the following code being generated instead:

    someField: z.string().default("Some\nThing").nullish(),

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