Mutations

Grafbase automatically generates mutations based on the types you define in your schema.

These mutations can be used to create, update, delete, link, or unlink data.

Mutations come in the following format, where [modelName] is the name of the model defined in your schema tagged with @model:

  • [modelName]Create: [modelName]CreatePayload
  • [modelName]Update: [modelName]UpdatePayload
  • [modelName]Delete: [modelName]DeletePayload

Each of the mutations return a [modelName][Action]Payload type.

The create mutation contains a single input argument that is used to capture the fields for the model you want to create data for. If a field is marked as non-nullable in your schema, the generated input type applies that validation, and thus the input must contain a non-null value for that field.

type Post @model {
  # ...
  title: String!
}

The update mutation contains two arguments that are required to update data:

  • id: ID! — The ID of the entry you want to update.
  • input: [modelName]UpdateInput! — The input type containing the fields for the model you want to update.
type Post @model {
  # ...
  title: String!
}

The delete mutation contains a single argument that is required for deleting data:

  • id: ID! — The ID of the entry you want to delete.
type Post @model {
  # ...
  title: String!
}

When your schema contains multiple, related types, nested mutations are then available to create, link, or unlink.

type Post @model {
  id: ID!
  title: String!
  category: Category
}

type Category {
  id ID!
  name: String!
  posts: [Post]
}