epistemik-co/staple-api

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:

Given this we could consider yet another approach:

  1. We force all _id and _value fields to be non-null
  2. Given a filter on _id or _value we force it to null if the filter condition is not satisfied
  3. 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 ;)