Skip to content

Non-null query arguments with a default value should be marked as optional #378

Open
@Ionaru

Description

@Ionaru

Expected Behavior

When I create a schema.graphql containing a non-null query argument that has a default value, I would expect to not have to pass that argument to the query.

Current Behavior

The type system gives me an error, asking me to add the query argument.

image

Possible Solution

The generation logic should treat non-null query arguments with a default value the same as if they were optional.
Relevant part of the spec: https://spec.graphql.org/October2021/#sec-Required-Arguments

Steps to Reproduce

  1. Create a schema.graphql like this:
type Row {
  id: ID!
}

type Query {
  rows(limit: Int! = 10): [Row!]!
}
  1. Run npx graphql-zeus@5.3.1 schema.graphql --typedDocumentNode
  2. Inspect zeus/index.ts:
...
export type ValueTypes = {
    ['Row']: AliasType<{
        id?: boolean | `@${string}`,
        __typename?: boolean | `@${string}`
    }>;
    ['Query']: AliasType<{
        // Here I would expect "limit" to be optional, because the default value is "10".
        rows?: [{ limit: number | Variable<any, string> }, ValueTypes['Row']],
        __typename?: boolean | `@${string}`
    }>
}
...

Additional information

  • Node.js version 18.17.1.
  • graphql-zeus version 5.3.1.
  • graphql version 16.8.0.
  • @apollo/client version 3.8.3.
  • Typescript version 5.1.6.
  • using typedDocumentNode for the Apollo client in Angular.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions