-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: source
Are you sure you want to change the base?
Conversation
@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. |
The committers listed above are authorized under a signed CLA. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
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
There was a problem hiding this comment.
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 !
)
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.