Skip to content

Commit

Permalink
Added docs for AND and OR filter combinators. (#2862)
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn authored Jan 12, 2021
1 parent 4e19dd5 commit 9512b4d
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions website/src/docs/hotchocolate/fetching-data/filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,65 @@ public class Query
}
```

# AND / OR Filter

There are two built in fields.

- `AND`: Every condition has to be valid
- `OR` : At least one condition has to be valid

Example:

```graphql
query {
posts(
first: 5
where: { OR: [{ title: {contains: "Doe" }}, { title: {contains: "John" }}] }
) {
edges {
node {
id
title
}
}
}
}
```

**⚠️ OR does not work when you use it like this: **

```graphql
query {
posts(
first: 5
where: { title: {contains: "John", OR: { title: {contains: "Doe" }}} }
) {
edges {
node {
id
title
}
}
}
}
```

In this case the filters are applied like `title.Contains("John") && title.Contains("Doe")` rather than `title.Contains("John") || title.Contains("Doe")` how you probably intended it.

## Removing AND / OR
If you do not want to expose `AND` and `OR` you can remove these fields with the descriptor API:

```csharp
public class PersonFilterType
: FilterInputType<Person>
{
protected override void Configure(IFilterInputTypeDescriptor<Person> descriptor)
{
descriptor.AllowAnd(false).AllowOr(false);
}
}
```

# Filter Types

## Boolean Filter
Expand Down

0 comments on commit 9512b4d

Please sign in to comment.