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

Argument need not be optional to have a default value defined #1703

Open
wants to merge 1 commit into
base: source
Choose a base branch
from

Conversation

gpj1
Copy link

@gpj1 gpj1 commented May 17, 2024

Closes #

Description

Current documentation about Arguments says that "When an argument is optional, we can define a default value ..."
This seems to be misleading because a default value for an argument can be defined irrespective of optional or mandatory argument.

Copy link

vercel bot commented May 17, 2024

@gpj1 is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

linux-foundation-easycla bot commented May 17, 2024

CLA Signed


The committers listed above are authorized under a signed CLA.

@benjie
Copy link
Member

benjie commented May 18, 2024

Interesting nuance; technically you can’t define a default value for a non-optional argument, since an optional argument is one that is either nullable or has a default value, but this is a bit if a circular argument! Thanks for bringing this to our attention, definitely feels like the wording could be cleaned up 👍

@@ -63,7 +63,7 @@ type Starship {

All arguments are named. Unlike languages like JavaScript and Python where functions take a list of ordered arguments, all arguments in GraphQL are passed by name specifically. In this case, the `length` field has one defined argument, `unit`.

Arguments can be either required or optional. When an argument is optional, we can define a _default value_ - if the `unit` argument is not passed, it will be set to `METER` by default.
Arguments can be either required or optional. We can define a _default value_ for an argument as well - if the `unit` argument is not passed, it will be set to `METER` by default.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

Suggested change
Arguments can be either required or optional. We can define a _default value_ for an argument as well - if the `unit` argument is not passed, it will be set to `METER` by default.
Arguments can be either required or optional. An argument is optional if its type is nullable or if it defines a _default value_. For the `length` field above, if the `unit` argument is not passed, it will be set to `METER` by default.

I think the code above should also be adjusted (and this change reflected as appropriate in the rest of the page), though that is not essential:

  length(unit: LengthUnit! = METER): Float

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(The change being the addition of the !)

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

Successfully merging this pull request may close these issues.

2 participants