flatbread
flatbread copied to clipboard
Cannot filter queries by keys in object arrays
The sift implementation currently uses positional assumptions on what you intend to filter.
To decode what that means, a filter argument is of the form filter: { title: { wildcard: "*tion" }}.
This assumes that the last keyname of the deepest nested object is the comparitor function, in this case it means, "use the regex wildcard function", and filters by the title field for all tuples matching the value *tion.
This assumption breaks down when you need to compare a field of an object on an array.
If we have an authors field on a Posts collection, we could imagine that data would be an array of author objects.
- the syntax of
filter: { authors: { name: { wildcard: "*tion" }}}isn't valid - nor is
filter: { authors: { wildcard: { name: "*tion" }}}
If we switch to a marker/keyword-based approach of parsing filters, we could avoid field name collision while also allowing objects to be passed as values:
filter: { authors: { _wildcard: { name: "*tion" }}}
Another option is to adopt a set of array-specific operations like Gridsome allows.
I believe it would be most desirable to allow multiple comparator operations like in the case of arrays, such as "filter elements in this collection by checking if this array field contains another field that is greater than or equal to this specified value"
The above ideas can actually all coexist and might make for a nice DX where, at a glance, you have insight into which keys of the filter object originate from Flatbread, similar to built-in fields.