graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Declare a mutation without any input variables

Open gorjanz opened this issue 8 years ago • 2 comments

Is it possible to declare and execute a mutation with no input variables? I realize it's an edge case, but I also think that it can be useful. So for example:

input WorkingInput {
  id: String!
}
type Response {
  result: Boolean!
}
type Mutation {
  doSomething(): Response!
  thisOneWorks($input: WorkingInput): Response!
}

I am using graphql-tools v2.7.2 and when the schema is being parsed the error is:

GraphQLError: Syntax Error GraphQL request (75:12) Expected Name, found )

for the doSomething() mutation. It seems it's always expecting a variable, before the closing parenthesis.

Is there any way to go around this? I could be wrong, but from what I read in the GraphQL specification, nowhere does it say that a Mutation can not be declared with no input variables. I can imagine wanting to invoke some action, which is pre-defined, where you just need the action to get executed, no need to supply any data.

gorjanz avatar Dec 11 '17 18:12 gorjanz

@gorjanz You have to leave out the parentheses, just as you do for other fields without arguments.

martijnwalraven avatar Dec 11 '17 19:12 martijnwalraven

@martijnwalraven thanks for the fast response. that works just as I would expect.

For everyone else that run into this problem, the correct form is:

type Response {
  result: Boolean!
}
type Mutation {
  doSomething: Response!
}

closing the issue... thanks again!

gorjanz avatar Dec 11 '17 20:12 gorjanz