-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Background
This is a very initial idea for allowing a shorthand for using/matching variables and arguments on a selection set.
In many projects we (The Guild) worked with, we saw this repeating pattern of using the same name for variables and arguments.
Proposal
Today we are doing the following in order to declare a variable, and match it with an argument:
query user($id: ID!) {
user(id: $id) {
# ...
}
}
But, if the variable and the argument have the same name, we should be able to do the following:
query user($id: ID!) {
user($id) {
# ...
}
}
So if the $id
is used as-is, without an explicit argument name, it will match the id
argument.
I think there is no real need to provide the argument name if it's the same as the variable name, and it will simplify the usage.
This is similar to the JS shorthand while working with objects, you can do { foo }
instead of { foo: foo }
.
I think this kind of shorthand can be implemented by changing a few lines of code in the parser
/ lexer
implementation: if there is a variable instead of an argument - we can just use the variable name as the argument name and the rest remains the same.