Mutations
In this page we describe the mutations that are automatically generated by Cedalio when you deploy a GraphQL schema.
Cedalio 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.Schema
Generated types
type Post @model {
title: String!
}
type Mutation {
postCreate(input: PostCreateInput!): PostCreatePayload
}
input PostCreateInput {
title: String!
}
type PostCreatePayload {
post: Post
}
mutation {
postCreate(input: { title: "Hello Cedalio" }) {
post {
title
}
}
}
{
"data": {
"postCreate": {
"post": {
"title": "Hello Cedalio"
}
}
}
}
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
.Schema
Generated types
Update by ID
Update by unique
type Post @model {
title: String!
slug: String! @unique
}
type Mutation {
postUpdate(by: PostByInput!, input: PostUpdateInput!): PostUpdatePayload
}
input PostByInput {
id: ID
slug: String
}
input PostUpdateInput {
title: String
slug: String
}
type PostUpdatePayload {
post: Post
}
mutation {
postUpdate(
by: { id: "post_AAAAAAAAAAAA0000000000" }
input: { title: "Hello Cedalio!" }
) {
post {
title
}
}
}
mutation {
postUpdate(
by: { slug: "hello-cedalio" }
input: { title: "Hello Cedalio" }
) {
post {
title
}
}
}
{
"data": {
"postUpdate": {
"post": {
"title": "Hello Cedalio"
}
}
}
}
Fields using the type
Int
have the input type IntOperationsInput
that lets you quickly increment
, decrement
, or set
values.Increment by 1
Decrement by 100
Set
mutation {
postUpdate(by: { id: "..." }, input: { likes: { increment: 1 } }) {
post {
likes
}
}
}
mutation {
postUpdate(by: { id: "..." }, input: { likes: { decrement: 100 } }) {
post {
likes
}
}
}
mutation {
postUpdate(by: { id: "..." }, input: { likes: { set: 1 } }) {
post {
likes
}
}
}
Fields using the type
Float
have the input type FloatOperationsInput
that lets you quickly increment
, decrement
, or set
values.
Increment by 1.0
Decrement by 100.0
Set
mutation {
postUpdate(by: { id: "..." }, input: { likes: { increment: 1.0 } }) {
post {
likes
}
}
}
mutation {
postUpdate(by: { id: "..." }, input: { likes: { decrement: 100.0 } }) {
post {
likes
}
}
}
mutation {
postUpdate(by: { id: "..." }, input: { likes: { set: 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.
Schema
Generated types
Delete by ID
Delete by unique
type Post @model {
title: String!
slug: String! @unique
}
type Mutation {
postDelete(by: PostByInput!): PostDeletePayload
}
input PostByInput {
id: ID
slug: String
}
type PostDeletePayload {
deletedId: ID!
}
mutation {
postDelete(by: { id: "post_AAAAAAAAAAAAA0000000000000" }) {
deletedId
}
}
{
"data": {
"postDelete": {
"deletedId": "post_AAAAAAAAAAAAA0000000000000"
}
}
}
mutation {
postDelete(by: { slug: "hello-cedalio" }) {
deletedId
}
}
{
"data": {
"postDelete": {
"deletedId": "post_AAAAAAAAAAAAAA000000000000"
}
}
}
When your schema contains multiple, related types, nested mutations are then available to create, link, or unlink.
Schema
Generated types
Create new category
Link existing category
Unlink existing category
type Post @model {
title: String!
category: Category
}
type Category {
name: String!
posts: [Post]
}
type Post {
category: Category
id: ID!
title: String!
}
type Category {
id: ID!
name: String!
posts: [Post]
}
input PostCreateInput {
category: PostCategoryRelatePostCategoryCreateRelationInput
title: String!
}
input PostCategoryRelatePostCategoryCreateRelationInput {
create: PostCategoryRelatePostCategoryCreateInput
link: ID
}
input PostUpdateInput {
category: PostCategoryRelatePostCategoryUpdateRelationInput
title: String
}
input PostCategoryRelatePostCategoryUpdateRelationInput {
create: PostCategoryRelatePostCategoryCreateInput
link: ID
unlink: ID
}
mutation {
postCreate(
input: {
title: "Hello Cedalio"
category: { create: { name: "Announcements" } }
}
) {
post {
title
category {
name
}
}
}
}
{
"data": {
"postCreate": {
"post": {
"title": "Hello Cedalio",
"category": {
"name": "Announcements"
}
}
}
}
}
mutation {
postCreate(
input: {
title: "Hello Cedalio"
category: { link: "category_AAAAAAAAAAAA000000000000" }
}
) {
post {
title
category {
name
}
}
}
}
{
"data": {
"postCreate": {
"post": {
"title": "Hello Cedalio",
"category": {
"name": "Announcements"
}
}
}
}
}
mutation {
postUpdate(
id: "post_01GD0BS8VS0S700MNK0ZK53414"
input: { category: { unlink: "category_AAAAAAAAAAAAAA0000000000000" } }
) {
post {
title
category {
id
}
}
}
}
{
"data": {
"postUpdate": {
"post": {
"title": "hello",
"category": null
}
}
}
}
Last modified 4mo ago