Summary
Add a setting that selects what QueryKit does when a filter or a sort uses a property with PreventFilter() or PreventSort():
- Ignore (default): QueryKit removes the filter clause or skips the sort clause. The rest of the filter or sort still runs.
- Throw: QueryKit throws a
QueryKitException subclass that names the property.
Current behavior
After the property resolver work, a prevented property is always ignored:
- The parser removes a prevented filter clause. This is true for the member name and for the query name.
SortParser skips a prevented sort clause.
Before that work, the behavior was not the same for all forms. A property with both PreventFilter() and PreventSort() threw InvalidOperationException (wrapped in a ParsingException) when the filter used its query name. With the member name, the same clause was removed.
Why a setting
Some APIs want to silently ignore fields that a client cannot use. Other APIs want to return a 400 so that the client knows that its filter or sort had no effect. Ignore stays the default, so current users see no change.
Proposed shape
var config = new QueryKitConfiguration(config =>
{
config.PreventedPropertyBehavior = PreventedPropertyBehavior.Throw; // default: Ignore
});
The name is only a proposal. The setting applies to filters and sorts.
When the setting is Throw:
- A filter clause on a property with
PreventFilter() throws. This includes the property on the right side, in arithmetic, and in a property list.
- A sort clause on a property with
PreventSort() throws.
- A derived property or a custom operation with
PreventFilter() or PreventSort() throws the same way.
- The exception derives from
QueryKitException, so a single catch handles it.
Out of scope
Allow-list mode (#108) is a separate feature.
Summary
Add a setting that selects what QueryKit does when a filter or a sort uses a property with
PreventFilter()orPreventSort():QueryKitExceptionsubclass that names the property.Current behavior
After the property resolver work, a prevented property is always ignored:
SortParserskips a prevented sort clause.Before that work, the behavior was not the same for all forms. A property with both
PreventFilter()andPreventSort()threwInvalidOperationException(wrapped in aParsingException) when the filter used its query name. With the member name, the same clause was removed.Why a setting
Some APIs want to silently ignore fields that a client cannot use. Other APIs want to return a 400 so that the client knows that its filter or sort had no effect. Ignore stays the default, so current users see no change.
Proposed shape
The name is only a proposal. The setting applies to filters and sorts.
When the setting is
Throw:PreventFilter()throws. This includes the property on the right side, in arithmetic, and in a property list.PreventSort()throws.PreventFilter()orPreventSort()throws the same way.QueryKitException, so a single catch handles it.Out of scope
Allow-list mode (#108) is a separate feature.