Under what scenarios does Dgraph return an array in place of a string?

with this you get an object instead of array.

[uid] .

with this above you get always an array.

Also reverse edges you always get arrays. No matter what.

why this line?

116		bar: 'uid(bar3)',

line 125, you are not using vars, you should use the main method instead.

        "bar_name": [
          "bar 2",
          "bar 3"
        ]

Looks like somehow your code transformed your bar_name into a list. Or maybe your code messup in the loop?