Skip to main content
Version: v3.x (DDN)

Basics of Mutations

Introduction

GraphQL mutations are used to modify data by invoking commands in your Hasura DDN project. Mutations allow you to insert, update, or delete records while maintaining control over what data is affected and returned.

Mutations can perform inserts to add new records, specifying values for each field in the command. You can also update existing records by applying changes to fields that match certain conditions. Similarly, you can delete records that meet specific criteria, ensuring precise control over which data is removed.

Just like queries, mutations allow you to specify fields in the response. This means you can retrieve the affected data after a mutation, such as returning the new or updated values of fields in the records you modified.

Since the GraphQL API is self-documenting, you can write mutations manually or use tools like auto-completion and the GraphiQL explorer in the Hasura DDN console to help you build and test them. GraphiQL shows the available mutation types, fields, and input arguments, making it easier to construct and validate mutations.

Configuration

Currently, you can perform mutations via the GraphQL API using the following methods:

  • Some data connectors support mutations out-of-the-box and — when adding commands that are procedures — will generate them automatically.
  • Some data connectors support authoring native mutations — such as with the MongoDB connector — to enable you to write custom logic for inserts, updates, and deletes.
  • You can mutate data via any lambda connector using the Command Query Separation (CQS) pattern. Learn more here.
Not sure what your connector supports?

For questions about feature support, check out the connector reference docs.

You can configure the overall usage of mutations in your GraphQL API using the GraphQlConfig object in your metadata. Additionally, you can customize individual mutations by modifying the GraphQlDefinition metadata object for a command.

Learn more