Skip to content

Proposal: Shorthand for variables/arguments on an operation #889

@dotansimha

Description

@dotansimha

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions