Hi!
I’m confused about that new JSON filter. If my JSON is just an array of strings (flat structure, no nested objects), how do I specify “right here, at the root” as a path? “@”, “$” or “.” are not accepted.
In more detail:
Directus 12.4.1 running with a postgresql backend. I have a collection named “persons”. That collection has a field called “vip_roles”. That field is defined in directus as “Dropdown (multiple)”.
Directus turns this into a field with JSON content. The API outputs this as
{
"vip_roles": ["role1", "role2“],
"other_fields": "..."
}
which is fine. But how can I specify a filter that I only want to see persons which have the vip_role “role1”?
h–ps://example.com/items/persons/?filter[vip_roles]=role1
gives “Invalid query. “json” field type does not contain the “_eq” filter operator.”,
h–ps://example.com/items/persons/?filter[vip_roles][_contains]=role1
gives “Invalid query. “json” field type does not contain the “_contains” filter operator.”
so I’m positive that I need the _json operator.
So after some experiments I was successful with the REST API:
h–ps://example.com/items/persons/?filter[vip_roles][_json][_contains]=role1
Note the empty path selector.
But how do I express this in GraphQL?
`query {
persons(
filter: {
vip_roles: { _json: {"": {_contains: "${role}"}}}
}
) {
id
first_name
last_name
}
}`
throws a GraphQL validation error. (Cannot see the error message)
I tried to replace those empty quotes with something else, anything that seems to describe “empty” or “right here”, but without success. [], {}, null, “$”, “@” … no luck.
