postlight / lux

Build scalable, Node.js-powered REST JSON APIs with almost no code.
https://lux.postlight.com
MIT License
570 stars 60 forks source link

Filtering by relationship values #699

Closed willviles closed 6 years ago

willviles commented 7 years ago

At present, support for filtering by relationship values is very limited.

It is possible to filter a belongsTo relationship by singular id value using a bit of a hack. For example, a user belongs to a permission group. We want to find all users with permission level 4:

http://localhost:4000/users?filter[permissionId]=4

Relationship ids

The query above should be represented by the relationship key without having to specify it as permissionId:

http://localhost:4000/users?filter[permission]=4

Multiple values should be able to be passed. For example, to get users with permissions of either 2 or 4:

http://localhost:4000/users?filter[permission]=2,4

Also hasMany relationships should accept single values or arrays of ids. For example, get all articles that are tagged with tag ID 8 or 10:

http://localhost:4000/articles?filter[tags]=8,10

Advanced filtering

Advanced filtering could allow for relationship values to be filtered. For example, selecting articles by tag name 'foo':

http://localhost:4000/articles?filter[tags][name]=foo

Also, taking #617 into consideration and allowing for filtering with > and < operators. For example, get all users with a permission id of greater than 2:

http://localhost:4000/users?filter[permission]=>2