Skip to content

Commit 26f301c

Browse files
authored
docs: logical operators (#308)
* docs: logical operators * Address feedback
1 parent 310d102 commit 26f301c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

website/pages/en/querying/graphql-api.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,58 @@ This can be useful if you are looking to fetch only entities whose child-level e
168168
}
169169
```
170170

171+
#### Logical operators
172+
173+
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.
174+
175+
##### `AND` Operator
176+
177+
In the following example, we are filtering for challenges with `outcome` `succeeded` and `number` greater than or equal to `100`.
178+
179+
```graphql
180+
{
181+
challenges(where: { and: [{ number_gte: 100 }, { outcome: "succeeded" }] }) {
182+
challenger
183+
outcome
184+
application {
185+
id
186+
}
187+
}
188+
}
189+
```
190+
191+
> **Syntactic sugar:** You can simplify the above query by removing the `and` operator by passing a sub-expression separated by commas.
192+
>
193+
> ```graphql
194+
> {
195+
> challenges(where: { number_gte: 100, outcome: "succeeded" }) {
196+
> challenger
197+
> outcome
198+
> application {
199+
> id
200+
> }
201+
> }
202+
> }
203+
> ```
204+
205+
##### `OR` Operator
206+
207+
In the following example, we are filtering for challenges with `outcome` `succeeded` or `number` greater than or equal to `100`.
208+
209+
```graphql
210+
{
211+
challenges(where: { or: [{ number_gte: 100 }, { outcome: "succeeded" }] }) {
212+
challenger
213+
outcome
214+
application {
215+
id
216+
}
217+
}
218+
}
219+
```
220+
221+
> **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.
222+
171223
#### All Filters
172224

173225
Full list of parameter suffixes:

0 commit comments

Comments
 (0)