DQL querying with an array of parameters

The documentation states:

Query parameterization

Parameters

  • must have a name starting with a ` symbol.
  • must have a type int, float, bool or string.
  • may have a default value. In the example below, $age has a default value of 95
  • may be mandatory by suffixing the type with a !. Mandatory parameters can’t have a default value.

Variables can be used in the query where a string, float, int or bool value are needed.

You can also use a variable holding uids by using a string variable and by providing the value as a quoted list in square brackets:
query title($uidsParam: string = "[0x1, 0x2, 0x3]") { ... }.

1. Documentaion should be more explicit

Explain how to use the param inside the DQL query, like so:

query test($uid: string = "[0x1, 0x2]"){
  test(func: uid($uid)) {
    uid
  }
}

2. Syntax

The right syntax shouldn’t be string = "[0x1, 0x2]"

But either:

  • string[] = [0x1, 0x2]
  • [string] = [0x1, 0x2]

3. Why can’t we just send arrays in general?

Then it would be nice to be able to send an array of strings for cases in where I want to match multiple strings:

query title($terms: string[] = ["foo", "bar"]){
  title(func: eq(title, $terms)) {
    uid
  }
}

This is possible:

{
  title(func: eq(title, ["foo", "bar"])) {
    uid
  }
}

But you can’t ever do this with params.

Related: DQL - querying with an array of strings not working when passed in as parameter

1 Like
1 Like

Oh, I don’t know how I missed that one, subbed to the issue.

I hope someone on the team addresses quality of life stuff like this and shows some signs of life…

Thanks :wink:

2 Likes

Following along-- will chat with the team is this is an enhancement we could add quickly.

2 Likes