Copying a list of linked objects in a predicate

Okay, now I get what is going on.

The Bulk Upsert won’t work for you. We would need a kind of loop in grapqhl+- to be able to do it. But for now, you have to do this in your business logic.

This code bellow, you have to perform a mutation for each existing company. So in this case you gonna use pagination (first and offset) to make it work. So as you have two companies. You have to run

1 - var(func:type(Company), first:1, offset:0 )
2 - var(func:type(Company), first:1, offset:1 )

{
  "query": "{ v as var(func:type(Company), first:1, offset:0 ) { p as projects } }",
  "set": {
    "uid": "uid(v)",
    "new_projects": [{ "uid": "uid(p)"}]
  },
  "delete": {
    "uid": "uid(v)",
    "projects": [{ "uid": "uid(p)"}]
  }
}

However, if you don’t want to use pagination. If it gets too complex. I recommend the approach below using a temporary edge called “migrationdone”. At the end of the day, you can just clean up these edges.

So, if you have thousands of companies to do this operation. You have to run this thousand times. It will skip those who have “migrationdone”.

{
  "query": "{ v as var(func:type(Company), first:1 ) @filter(NOT has(migrationdone)) { p as projects } }",
  "set": {
    "uid": "uid(v)",
    "new_projects": [{ "uid": "uid(p)"}],
    "migrationdone": true
  },
  "delete": {
    "uid": "uid(v)",
    "projects": [{ "uid": "uid(p)"}]
  }
}

Let me know if that works for you.

PS. Maybe it can be done in Bulk Upsert using Conditional Upsert. Need to explore this idea.

Cheers.