GraphQL mutations create and modify objects, similar to a PUT, POST, or DELETE request in REST. Mutation requests are sent to the same endpoint as query requests.
A list of all mutations available on Tribe's GraphQL API is available here under Mutations section.
Mutations have the following structure:
- The mutation field name, such as
- The input data to use in the mutation passed as an argument, such as the information for a new space
- A selection of return fields that should be included in the response, such as the ID of the successfully created Space object
Mutations require input data, such as the data to create a new object, or the ID of an object to delete. For mutations that might require a substantial data object, the schema provides a dedicated input object type.
For example, the
createSpace mutation requires an input argument, which accepts a
CreateSpaceInput object. The
CreateSpaceInput type defines all the fields that can be used to create or modify a space.
We will cover what
collectionId id later in this guide.
Each mutation provides a set of fields that can be returned in the response. For example, one of the return fields available for the
createSpace mutation is the Space object that was created by a successful mutation. Similar to a GraphQL query, you can select the fields on the new object that you want to include in the response.
The following mutation uses input objects and return fields to create a new space and return their ID, name, and slug.