Feature: Add foreach() function. #5335
Labels
area/querylang/function
area/upsert
Issues related to upsert operations.
dgraph
Issue or PR created by an internal Dgraph contributor.
exp/expert
Deeply technical issue not recommended to beginners.
kind/feature
Something completely new we should consider.
status/needs-attention
This issue needs more eyes on it, more investigation might be required before accepting/rejecting it
Experience Report
What you wanted to do
I would like to use loops in queries and upsert blocks. In this case something similar to "foreach".
What you actually did
There's nothing similar to this in Dgraph right now.
Why that wasn't great, with examples
A loop like foreach would be very useful. There are situations that we want to iterate over objects in a query. Whether to display a particular form structure in the response or to create specific mutations in the upsert block. Which is not currently supported in Dgraph.
Syntax
I believe that Syntax from foreach would be very similar to the K-shortest path.
More examples
I think a "foreach" func would be the solution for almost all the things like "groupby value".
Ref of a DB doing something similar to it:
https://neo4j.com/docs/cypher-manual/current/clauses/foreach/
https://docs.mongodb.com/manual/reference/method/cursor.forEach/
A foreach loop could solve this issue #4779 in a blink of an eye (eliminating the misuse of an extra block). I gonna add a comment there with an example using "foreach".
In this link https://discuss.dgraph.io/t/foreach-func-in-graphql-loops-in-bulk-upsert/5533 I have other use cases. Most of them related to upsert block, issues with Facets bad responses (e.g: #4160), and so on.
e.g: "for each group found in groupby create a new object to use in response".
Desirable Result
Any external references to support your case
https://discuss.dgraph.io/t/foreach-func-in-graphql-loops-in-bulk-upsert/5533
The text was updated successfully, but these errors were encountered: