defradb
defradb copied to clipboard
Enable documents filtering by inline array fields
currently we allow filtering of documents by related objects:
query {
Author(filter: {
books: {rating: {_gt: 3}}
}) {
name
books {
name
}
}
}
But there is no way we can do it for inline arrays like [String]
.
One of the ideas is to introduce new operators _all
, _any
and _none
that should count number of filter matches for every element in the array:
query {
Author(filter: {
genres: {_any: {_eq: "Horror"}}
}) {
name
}
}
query {
Author(filter: {
publishedYears: {_all: {_gt: 2010}}
}) {
name
}
}
Alternatively (or additionally) we can integrate aggregates into filters with their own filters within:
query {
Author(filter: {
_count(books: { filter: {
rating: {_gt: 3}
}}): {_eq: 2}
}) {
name
}
}
This would allow us to specify exactly how many matching elements should be in the array.
Tangentially related idea: it might be also useful to request indexes of matching elements into the array and potentially afterwards use them to manipulate the array.