Graphql mutations without arguments

There is nothing in the GraphQL spec that specifically requires one or more arguments for a mutation. In terms of arguments, there's nothing special about either query or mutation -- they are both fields themselves, and therefore can accept (or not) arguments like any other field. From the spec:

Inputs (such as field arguments), are always optional by default. However a non‐null input type is required. In addition to not accepting the value null, it also does not accept omission. For the sake of simplicity nullable types are always optional and non‐null types are always required.

In other words, the only time you have to have an argument is when one is defined in the schema and it's non-null.


If a mutation doesn't declare any parameters than it must looks this way:

mutation {
  createFoo : Payload
}

So you just must not to write parentheses at all.


With the graphql-request package in React you can do:

const query = gql`
  query {
    queryName {
      someProperty
    }
  }
`