Skip to content

Feature request: setting to ignore or throw for filters and sorts on prevented properties #112

Description

@pdevito3

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions