Contember offers advanced mutations for data modification. For every entity there are 3 operations available - create, update and delete. A GraphQL schema for your entity Post will look like this:
create mutation you can create new records. Under
node field you can fetch inserted record with a generated identifier.
update mutation to change existing record. For this operation, you need an unique identifier of the record. It can be either an ID or any other custom unique field. Using
node field, you can fetch updated record.
delete mutation you can delete records. You also need a unique identifier for this operation. Using
node field you can fetch a record before it is actually deleted.
In a single mutation, you can execute nested mutations on relations using this operations:
connect- connects a record you specify by unique identifier.
disconnect- disconnects record. For "has many" relations, you have to identify a record using unique identifier
create- creates a record and connects it automatically after that.
update- updates referenced record. For "has many" relations, you have to identify a record using unique identifier
delete- deletes referenced record. For "has many" relations, you have to identify a record using unique identifier
upsert- updates given record or creates a new record when there is nothing to update
If you are e.g. connecting a record, which does not exist, the mutation will fail.
Each mutation (with its nested mutations) is wrapped into individual transaction, meaning that for query:
There will be two database transaction.
If you need to wrap it into a single transaction, use
If anything goes wrong, whole transaction is rolled back.
As you can see in the example, you can get the result of mutation (
ok field but also errors, validation etc.) on both levels.
Currently there are no mutations for batch updates available. But you can always connect to a PostgreSQL and execute an update using SQL.