Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Ionaru opened this issue Sep 18, 2023 · 0 comments
Open

Comments

@Ionaru
Copy link

Ionaru commented Sep 18, 2023

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 [email protected] 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant