Skip to content

Commit

Permalink
docs: logical operators (#308)
Browse files Browse the repository at this point in the history
* docs: logical operators

* Address feedback
  • Loading branch information
saihaj authored Mar 10, 2023
1 parent 310d102 commit 26f301c
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions website/pages/en/querying/graphql-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,58 @@ This can be useful if you are looking to fetch only entities whose child-level e
}
```

#### Logical operators

As of Graph Node [`v0.30.0`](https://github.com/graphprotocol/graph-node/releases/tag/v0.30.0) you can group multiple parameters in the same `where` argument using the `and` or the `or` operators to filter results based on more than one criteria.

##### `AND` Operator

In the following example, we are filtering for challenges with `outcome` `succeeded` and `number` greater than or equal to `100`.

```graphql
{
challenges(where: { and: [{ number_gte: 100 }, { outcome: "succeeded" }] }) {
challenger
outcome
application {
id
}
}
}
```

> **Syntactic sugar:** You can simplify the above query by removing the `and` operator by passing a sub-expression separated by commas.
>
> ```graphql
> {
> challenges(where: { number_gte: 100, outcome: "succeeded" }) {
> challenger
> outcome
> application {
> id
> }
> }
> }
> ```
##### `OR` Operator
In the following example, we are filtering for challenges with `outcome` `succeeded` or `number` greater than or equal to `100`.
```graphql
{
challenges(where: { or: [{ number_gte: 100 }, { outcome: "succeeded" }] }) {
challenger
outcome
application {
id
}
}
}
```
> **Note**: When constructing queries, it is important to consider the performance impact of using the `or` operator. While `or` can be a useful tool for broadening search results, it can also have significant costs. One of the main issues with `or` is that it can cause queries to slow down. This is because `or` requires the database to scan through multiple indexes, which can be a time-consuming process. To avoid these issues, it is recommended that developers use and operators instead of or whenever possible. This allows for more precise filtering and can lead to faster, more accurate queries.
#### All Filters

Full list of parameter suffixes:
Expand Down

0 comments on commit 26f301c

Please sign in to comment.