# Query and mutate in one request

**URL:** <https://discuss.dgraph.io/t/query-and-mutate-in-one-request/2390>\
**Category:** Dgraph\
**Created:** [March 29, 2018, 1:32pm UTC](https://discuss.dgraph.io/t/query-and-mutate-in-one-request/2390 "2018-03-29T13:32:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddibiase](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ddibiase/32/1157_2.png) [@ddibiase](https://discuss.dgraph.io/u/ddibiase)\
**Post date:** [March 29, 2018, 1:32pm UTC](https://discuss.dgraph.io/t/query-and-mutate-in-one-request/2390/1 "2018-03-29T13:32:05Z")

</div>

I’m wondering if there’s a way to perform a query and mutation in the same query. If I remember correctly in older versions (before transactions were implemented) we were able to run queries that collected results and performed mutations. Forgive the syntax below but it demonstrates briefly what I’m looking to accomplish:

```
{
   var(func: has(Postings)) {
       Postings as uid
   }
   mutation {
      <0x938574> <Result> uid(Postings)
   }
}

```

Basically want to collect a list of UIDs and make edges from there.

Thanks!

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [March 31, 2018, 5:11am UTC](https://discuss.dgraph.io/t/query-and-mutate-in-one-request/2390/2 "2018-03-31T05:11:11Z")

</div>

In transactions, we had removed the query + mutations mix, due to that logic getting overly complex. I think we’ll reintroduce this functionality once we support Cypher, which has directives for updates.

---

<div class="post-metadata">

**Author:** ![ddibiase](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ddibiase/32/1157_2.png) [@ddibiase](https://discuss.dgraph.io/u/ddibiase)\
**Post date:** [March 31, 2018, 11:04pm UTC](https://discuss.dgraph.io/t/query-and-mutate-in-one-request/2390/3 "2018-03-31T23:04:28Z")

</div>

Is there an easy way to do so with a transaction or will I have to a) query all the UIDs get the result back, b) within my application structure the mutation and then c) commit the whole transaction?

Would there be ANY way to avoid sending the UIDs back to my application and mutate them directly to replicate the old query + mutation mix?

---

<div class="post-metadata">

**Author:** ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)\
**Post date:** [April 2, 2018, 11:21pm UTC](https://discuss.dgraph.io/t/query-and-mutate-in-one-request/2390/4 "2018-04-02T23:21:34Z")

</div>

> [@ddibiase](#):
>
> Would there be ANY way to avoid sending the UIDs back to my application and mutate them directly to replicate the old query + mutation mix?

There is no way right now, though we will probably introduce something soon.

---

<div class="post-metadata">

**Author:** ![ekkis](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ekkis/32/1163_2.png) [@ekkis](https://discuss.dgraph.io/u/ekkis)\
**Post date:** [April 10, 2018, 2:23am UTC](https://discuss.dgraph.io/t/query-and-mutate-in-one-request/2390/5 "2018-04-10T02:23:50Z")

</div>

introducing Cypher would make this product 1M times better. GraphQL+ just sucks

---

<div class="post-metadata">

**Author:** ![BlankRain](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/blankrain/32/1592_2.png) [@BlankRain](https://discuss.dgraph.io/u/BlankRain)\
**Post date:** [June 12, 2018, 6:07am UTC](https://discuss.dgraph.io/t/query-and-mutate-in-one-request/2390/6 "2018-06-12T06:07:03Z")

</div>

😂  
just like SQL .  
` update somenode set something=somevalue where something is cool`

I do want to do mutation with filters .

---

<div class="post-metadata">

**Author:** ![shanghai-Jerry](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/shanghai-jerry/32/863_2.png) [@shanghai-Jerry](https://discuss.dgraph.io/u/shanghai-Jerry)\
**Post date:** [June 13, 2018, 9:31am UTC](https://discuss.dgraph.io/t/query-and-mutate-in-one-request/2390/7 "2018-06-13T09:31:20Z")

</div>

i tried to use db to save uids that dgraph returned and you can query uid from db. you also can use this db to provide a service to search uid, before you insert data to dgraph you can try to ask the db if this data exist already in dgraph

> [@ddibiase](#):
>
> Basically want to collect a list of UIDs and make edges from there.

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [June 16, 2020, 3:48pm UTC](https://discuss.dgraph.io/t/query-and-mutate-in-one-request/2390/8 "2020-06-16T15:48:41Z")

</div>

> [@ddibiase](#):
>
> Would there be ANY way to avoid sending the UIDs back to my application and mutate them directly to replicate the old query + mutation mix?

We introduced `upsert` block last year, which can achieve this functionality now. It is documented here:

[https://dgraph.io/docs/mutations/#upsert-block](https://dgraph.io/docs/mutations/#upsert-block)
