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:
[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:
by: [modelName]ByInput!
— Theinput [modelName]ByInput
type containsid
and all other uniques for the model.input: [modelName]UpdateInput!
— The input type containing the fields for the model you want to update.
The mutation return the type [modelName]UpdatePayload
.
type Post @model {
title: String!
slug: String! @unique
}
Fields using the type Int
have the input type IntOperationsInput
that lets you quickly increment
, decrement
, or set
values.
mutation {
postUpdate(by: { id: "..." }, input: { likes: { increment: 1 } }) {
post {
likes
}
}
}
Fields using the type Float
have the input type FloatOperationsInput
that lets you quickly increment
, decrement
, or set
values.
mutation {
postUpdate(by: { id: "..." }, input: { likes: { increment: 1.0 } }) {
post {
likes
}
}
}
The delete mutation contains a single argument that is required for deleting data:
by: [modelName]ByInput!
— Theinput [modelName]ByInput
type containsid
and all other uniques for the model.
type Post @model {
title: String!
slug: String! @unique
}
When your schema contains multiple, related types, nested mutations are then available to create, link, or unlink.
type Post @model {
title: String!
category: Category
}
type Category {
name: String!
posts: [Post]
}