Create todos - mutation

In this part of the tutorial, you will learn how to create new todos by using GraphQL Mutations.

Let's define a GraphQL query to do a mutation into todos.

mutation addTodo($title: String!, $isPublic: Boolean!) {
action: insert_todos(objects: { title: $title, is_public: $isPublic }) {
returning {
id
title
is_completed
}
}
}

You will also need to pass in the values for the variables. To pass the variables copy the below code in Query variable section in GraphiQL.

{
"title": "My first todo",
"isPublic": true
}

Try this mutation in GraphiQL against the application database to see what the response looks like.

Let's now integrate this GraphQL mutation into our flutter app.

Close

Get Started with GraphQL Now

Hasura Cloud gives you a fully managed, production ready GraphQL API as a service to help you build modern apps faster.