Comment on page
GraphQL Mutations
How-to use mutations to insert data into the ObjectBox GraphQL database
Note: The GraphQL playground can also be used for mutations.
There are mutation operations for all entity types. For each entity, the following mutations are available: put* and delete*, where * signifies entity name. So for a
TestEntity
, the available mutations are putTestEntity
, deleteTestEntity
. All ObjectBox GraphQL mutations require an argument. For put operations, we indicate the types and values of objects to put, while when deleting we indicate the ids of objects to be deleted, or use the
all
flag to delete all objects. Refer to the examples below to see how these have to be formatted in each case.Optionally, you can use the
returning
section to make your mutation return the ID(s) of object(s) that were put or deleted.To put an object into the ObjectBox database, use
putTestEntity
for an ObjectBox entity called TestEntity, providing the object's type and value inside an input
argument. This works both for putting new objects and updating existing ones (in the latter case an id
must be supplied).mutation putOne {
putTestEntity(
input: {simpleBoolean: true}
) {
returning {
id
}
}
}
input
can also be an array.mutation putMultiple {
putTestEntity(
input: [
{simpleString: "banana"},
{simpleString: "orange"},
{simpleString: "banana"}
]) {
returning {
id
}
}
}
Supply an array of IDs to be deleted.
mutation deleteById {
deleteTestEntity(ids: [1, 3, 4, 42]) {
id
}
}
To delete all objects, set the
all
argument to true
.mutation deleteAll {
deleteTestEntity(all: true) {
id
}
}
Last modified 7mo ago