Combine several mutations in one request

Hi,

Is it possible to send several mutations in one request?
I could only find docs about queries…

Thanks,
Spinelsun

off-topic - this was a GraphQL question, not DQL

Technically each object in the mutation array is a “mutation”. I mean, You can send several changes like delete a bunch of nodes - do an SPO, SP*, or S**. But you can’t use multiple operations. Like “Set” and “Delete” at the same time.

Ok so if I want to insert several new elements I need to do n requests where n is the number of elements I want to insert, right?

off-topic - this was a GraphQL question, not DQL

Ah, BTW, my statement was with the JSON mutation in mind.
The RDF looks the same tho.

{
  set {
    <0x1> <name> "Julian" . # Each RDF line is basically a mutation change.
    <0x2> <name> "Rafael" . # You can mutate as much entities as you need.
    <0x3> <name> "Jack" .
  }
}

An example of multiple patterns with Delete

{
  delete {
     <0x1> <died> "1998" .  #SPO pattern
     <0x2> <name> * . #SP* pattern
     <0x3> * * .  #S** pattern
  }
}

In JSON

{
  "set": [
    {
      # One JSON obj in here
    },
    {
      # Another JSON obj in here for multiple operations
    }
  ]
}
{
  "delete": [
    {
      "uid": "0xa" // S * * pattern
    },
    {
      "uid": "0xf",
      "name": "Lucas" // S P O pattern
    },
    {
      "uid": "0xd",
      "name": null // S P * pattern
    }
  ]
}

I’m not sure about what you ask. What is the objective of combining several mutations? What do you mean exactly? A single mutation can do several moves in the DB. I don’t see what is the point.

Maybe you wanna do transactions? You can combine mutations in a transaction and finally commit. That works for you?

In GraphQL you can send multiple queries and mutations in a single request and pick which ones to run. Inside of a query block or mutation block you can have multiple queries and mutations respectively. With a subscription it can only be a single root node.

Oh! my bad, it is a GraphQL question! LOL sorry.

Let me just direct you to the spec on this one,

GraphQL (§ 2.2)

I also recommend reviewing § 2.3, 2.4, and 2.7. This will help you see also how to use the same mutation multiple time with aliases. Think of it like a JSON object. Any property name inside of a JSON object can only exist once for it to be a valid object. So the way around this is to use aliases.

Here is an example of a double mutation block in Dgraph’s GraphQL docs:

https://dgraph.io/docs/graphql/mutations/mutations-overview/#multiple-fields-in-mutations

What is the value of sending an operation with many queries if I can choose only one at a time?

Right now, just one at a time, but see: Batch API for GraphQL for RFC issues open

Sounds very good