Implement `only` and `contains` filters.
Closed this issue · 2 comments
The only
argument should appear on all _id
and _value
fields. The meaning of:
_id (only:["http://myuri"]
and
_value (only:["test value 1", "test value 2"])
is that only entities\literal with _id
/_value
on the provided list should be included in the response.
The contains
filter should appear on _value
fields (in the future only on strings). The meaning of:
_value (contains:"test")
is that only literals that contain the provided string as their substring should be included.
I don't know if it can be implemented as such, because there is no access to the only variable on the parent level.
I found another way to implement filtering in this article:
https://www.prisma.io/blog/designing-powerful-apis-with-graphql-query-parameters-8c44a04658a9
We can implement it this way or dig deeper.
Posting here for possible future reference:
- https://stackoverflow.com/questions/37969096/graphql-query-only-not-null-objectsm
- graphql/graphql-spec#275
- https://medium.com/@calebmer/when-to-use-graphql-non-null-fields-4059337f6fc8
Given this we could consider yet another approach:
- We force all
_id
and_value
fields to be non-null - Given a filter on
_id
or_value
we force it to null if the filter condition is not satisfied - Based on the non-null requirement in the schema, GraphQL converts the entire object / literal into null, and we stop here... This will however mean, that some lists will contain
null
inside them. We might be able to filter them out though if we torture GraphQL long enough ;)