GraphQL Variables (list)

I am trying to figure out if DGraph supports a way to pass in a list of UIDs via the GraphQL Variables API call.

Examples:

This unfortunately does not work -

query GetStuff($uids: string = "0xa105,0xa11d,0xa101") {
  operators(func:type("Thing"))
  @filter(uid($uids))
  {    uid    name    }
}

This does work, but it doesn’t use variables:

query GetStuff {
  operators(func:type("Thing"))
  @filter(uid("0xa105","0xa11d","0xa101"))
  {    uid    name    }
}

This also works, although the uids are not even strings here.

query GetStuff {
  operators(func:type("Thing"))
  @filter(uid(0xa105,0xa11d,0xa101))
  {    uid    name    }
}

Any other alternatives that I can use? Or is there no escape other than building the big query string in my code and not using variables at all?

That feels like an enhancement, please fill up an issue.

Actually, nevermind, I’ve just remembered about this PR Support for Gql variable in arrays by srfrog · Pull Request #2981 · dgraph-io/dgraph · GitHub and I thought about testing the hypothesis on this issue. And it worked.

query GetStuff($uids: string = "[0x1,0x2,0xa101]") {
  operators(func: uid($uids)) {    
     uid    
     name
    }
}

Result

{
  "data": {
    "operators": [
      {
        "uid": "0x1"
      },
      {
        "uid": "0x2"
      },
      {
        "uid": "0xa101"
      }
    ]
  }
}
1 Like

Excellent! Thank you very much.