GraphQL, possible to filter on multiple values?


#1

Using the graphQL query interface is there a mechanism to filter on multiple values? I was previously querying cayley with gizmo, and was able to filter on multiple values there, by passing an array of string values to the second parameter of the has function (though this does not seem to be documented, it does work). With the Graph QL, I’m not seeing anything that would allow me to filter on multiple values something like:

{ nodes(type:“Car”, model:[“ford”,“toyota”,“gm”]){type,model}

In gizmo I could do this by writing something like g.Vertex().Has(“type”,“Car”).Has(“model”, [“ford”,“toyota”,“gm”]).All()

I’m taking a first look at graphQL, as I’ve run into some performance issues with gizmo, which could very well be a poorly crafted query, still experimenting to find the balance between the do everything in a single query, versus multiple queries. My workaround for graphQL would be to send multiple queries, but that may not be ideal if there were a large number of car models in this example.

I did see a topic touching on this in a a discussion about collaboration between a common graphql like language between dgraph, and cayley, one of the customizations that that thread talked about was dgraph added custom support for filter filtering on multiple values. Which lead me to wonder if there is anything in place in cayley graphql which would allow for filtering on multiple values?


#2

Multiple values are not supported yet, but it should be easy to implement.

Opened an issue to track the progress: https://github.com/cayleygraph/cayley/issues/713


#3

This was a bit of misinformation from my side - Cayley already supports filters on multiple values.

Your examples should work:

{ nodes(type:"Car", model:["ford”, "toyota", "gm"]){type,model}

Assuming the following data is loaded:

<a> <type> "Car" .
<a> <model> "ford" .

#4

Thanks, I will retest this scenario


#5

Just tested version verison 0.7.4, that syntax actually doesn’t work, the parser does not appear to be expecting an array for the attribute value, executing in the web interface you get this error:
{
“data”: null,
“errors”: [
{
“message”: “Syntax Error GraphQL (3:28) Expected :, found String “ford”\n\n2: \n3: nodes(type:“Car”, model:[“ford”,“toyota”])\n ^\n4: {\n”,
“locations”: null
}
]
}

Data set:

<a> <type> "Car" .
<a> <model> "ford" .
<b> <type> "Car" .
<b> <model> "toyota" .

Invocation:
cayley http -i ./data/cars.nq -d memstore --host=:64210

Query:{

nodes(type:“Car”, model:[“ford”,“toyota”])
{
type

}
}


#6

For future reference, this actually does work, the problem was that you need a space between the colon, and the brace of the array, so it should be model: [. With that change it works