Mutations
Graphback provides three mutation types for every model.
create<Type>
: create a new item in the database of and return the created object in the response.update<Type>
: update an existing item in the database and return the updated object in the response.delete<Type>
: delete a single item in the database and return the deleted object in the response.
#
CreateThe create
mutation allows the client to insert a new item in the database.
The mutation follows the naming format create<Type>
:
Arguments:
input
: input type created by Graphback for creating a newNote
object.
Graphback creates a Create<Type>Input
input type for each of the data models you define, where the create
configuration is enabled. Relationship object fields in models map to the foreign key field in the database.
Each input field in Create<Type>Input
directly maps to the fields in the model. With the exception of the primary field, each field added to the input type preserves field nullability from the original model.
note
Primary fields will be nullable in the input type as they are often auto-generated by the database.
Take the following Note
model as an example.
The CreateNoteInput
input type is created from the Note
model.
Example of a typical create mutation on Note
:
You can also perform create
mutations on models with GraphQL type fields which map to a JSON column or an embedded document (MongoDB):
Graphback generates the appropriate input types for regular types that do not map to any database table/collection but are used as a field in a model.
You can create a new Note
with NoteMetadata
in a single mutation:
#
UpdateThe update
mutation allows the client to update an existing item in the database.
The mutation follows the naming format update<Type>
:
Arguments:
input
: input type created by Graphback for updating an existingNote
object.
Graphback creates a Mutate<Type>Input
input type for each of the data models you define, where either the update
or delete
configuration is enabled. Relationship object fields in models map to the foreign key field in the database.
With the exception of the primary field, all input fields are set to nullable to allow for partial updates. Graphback uses the primary field to ensure the correct item is being updated.
Take the following Note
model as an example.
The MutateNoteInput
input type is created from the Note
model.
Example of a typical create mutation on Note
:
You can also perform update
mutations on models with GraphQL type fields which map to a JSON column or an embedded document (MongoDB):
Graphback generates the appropriate input types for regular GraphQL types that do not map to any database table/collection but are used as a field in a model.
You can update an existing Note
with NoteMetadata
in a single mutation:
#
DeleteThe delete
mutation allows the client to delete an existing item from the database.
The mutation follows the naming format delete<Type>
:
Arguments:
input
: input type created by Graphback for updating an existingNote
object.
Graphback creates a Mutate<Type>Input
input type for each of the data models you define, when either the the delete
or update
CRUD configuration is enabled.
With the exception of the primary field, all input fields are set to nullable. Graphback uses the value from the primary field to ensure the correct is being deleted.
Take the following Note
model as an example.
The MutateNoteInput
input type is created from the Note
model. Each input field in MutateNoteInput
maps to the fields defined in Note
.
Example of a typical delete
mutation on Note
: