The two types of allowed operations in Pay’nUp GraphQL API are queries and mutations. Comparing GraphQL to REST, queries operate like GET requests, while mutations operate like POST/PATCH/DELETE. The mutation name determines which modification is executed.

Queries and mutations share similar forms, with some important differences.

About queries

GraphQL queries return only the data you specify. To form a query, you must specify fields within fields (also known as nested subfields) until you return only scalars.

Queries are structured like this:

query {
  JSON objects to return
}

About mutations

To form a mutation, you must specify three things:

  1. Mutation name: The type of modification you want to perform.
  2. Input object: The data you want to send to the server, composed of input fields. Pass it as an argument to the mutation name.
  3. Payload object: The data you want to return from the server, composed of return fields. Pass it as the body of the mutation name.

Mutations are structured like this:

mutation {
  mutationName(input: {MutationNameInput!}) {
    MutationNamePayload
}

The input object in this example is MutationNameInput, and the payload object is MutationNamePayload.

In the mutations reference, the listed input fields are what you pass as the input object. The listed return fields are what you pass as the payload object.

Variables can make queries more dynamic and powerful, and they can reduce complexity when passing mutation input objects.