From 9e54a5c7af872b6a5c88cc7672bad7547887c3ef Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Thu, 9 Mar 2023 14:15:05 -0500 Subject: [PATCH 1/2] docs: logical operators --- website/pages/en/querying/graphql-api.mdx | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/website/pages/en/querying/graphql-api.mdx b/website/pages/en/querying/graphql-api.mdx index 986d7bf15c35..92e8a4aca7ab 100644 --- a/website/pages/en/querying/graphql-api.mdx +++ b/website/pages/en/querying/graphql-api.mdx @@ -168,6 +168,56 @@ This can be useful if you are looking to fetch only entities whose child-level e } ``` +#### Logical operators + +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 + } + } +} +``` + #### All Filters Full list of parameter suffixes: From e7a0b25cdbde401adfa6464b60f5a1a96f316ddd Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Thu, 9 Mar 2023 15:37:20 -0500 Subject: [PATCH 2/2] Address feedback --- website/pages/en/querying/graphql-api.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/pages/en/querying/graphql-api.mdx b/website/pages/en/querying/graphql-api.mdx index 92e8a4aca7ab..20fcbe927692 100644 --- a/website/pages/en/querying/graphql-api.mdx +++ b/website/pages/en/querying/graphql-api.mdx @@ -170,7 +170,7 @@ This can be useful if you are looking to fetch only entities whose child-level e #### Logical operators -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. +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 @@ -218,6 +218,8 @@ In the following example, we are filtering for challenges with `outcome` `succee } ``` +> **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: