pub struct MutationBuilder { /* private fields */ }Expand description
Builder for GraphQL mutations (insert, update, delete).
§Examples
ⓘ
// Insert
let result = client.insert_into("blogCollection")
.objects(vec![json!({"title": "New", "body": "Content"})])
.returning(&["id", "title"])
.execute::<BlogRow>().await?;
// Update
let result = client.update("blogCollection")
.set(json!({"title": "Updated"}))
.filter(GqlFilter::eq("id", 1))
.at_most(1)
.returning(&["id", "title"])
.execute::<BlogRow>().await?;
// Delete
let result = client.delete_from("blogCollection")
.filter(GqlFilter::eq("id", 1))
.at_most(1)
.returning(&["id"])
.execute::<BlogRow>().await?;Implementations§
Source§impl MutationBuilder
impl MutationBuilder
Sourcepub fn returning(self, fields: &[&str]) -> Self
pub fn returning(self, fields: &[&str]) -> Self
Set the fields to return in the mutation result.
Sourcepub fn set(self, values: Value) -> Self
pub fn set(self, values: Value) -> Self
Set the values to update (for update mutations).
The value should be a JSON object with field names and new values.
Sourcepub fn objects(self, objects: Vec<Value>) -> Self
pub fn objects(self, objects: Vec<Value>) -> Self
Set the objects to insert (for insert mutations).
The value should be a JSON array of objects.
Sourcepub fn build(&self) -> (String, Value)
pub fn build(&self) -> (String, Value)
Build the mutation string and variables without executing.
Returns (query_string, variables) for inspection or debugging.
Sourcepub async fn execute<T: DeserializeOwned>(
self,
) -> Result<MutationResult<T>, GraphqlError>
pub async fn execute<T: DeserializeOwned>( self, ) -> Result<MutationResult<T>, GraphqlError>
Execute the mutation and return a typed MutationResult<T>.
The response is expected to have the shape:
{ "mutationField": { "affectedCount": N, "records": [...] } }
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MutationBuilder
impl !RefUnwindSafe for MutationBuilder
impl Send for MutationBuilder
impl Sync for MutationBuilder
impl Unpin for MutationBuilder
impl UnsafeUnpin for MutationBuilder
impl !UnwindSafe for MutationBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more