graphql / graphql-spec

GraphQL is a query language and execution engine tied to any backend service.
https://spec.graphql.org
14.26k stars 1.12k forks source link

positional (unnamed) arguments #411

Open sorenbs opened 6 years ago

sorenbs commented 6 years ago

In my experience there are many cases where it is beneficial to be able to have a directive with a single unnamed argument:

@import("some import specification") instead of @import(defs: "some import specification")
@default("some default value") instead of @default(value: "some default value")
@calculated("some expression") instead of @calculated(expression: "some expression")

There are multiple ways this could be allowed ranging from a general concept of positional arguments to a narrow special case for directives with a single argument.

Questions

  1. Has positional arguments been discussed before?
  2. Does anyone else have use cases that would benefit from positional arguments?
leebyron commented 5 years ago

Sorry this has sat so long. #426 was merged in, which I think answers your question #2, and yes positional arguments was discussed before open sourcing GraphQL.

The primary concern which I'd want to see addressed is schema evolution. So for example:

# Example definition
directive @log(message: String)

# Example usage
@log("wow")

# Future evolution...
directive @log(level: String, message: String)

The schema evolution above of adding an argument to a field/directive is currently considered non-breaking. However supporting the use of unnamed positional args would make adding arguments a breaking change since they would introduce ambiguity.