From 86605a18d3976392ce028a2d80c42df9c2d23115 Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Thu, 9 Mar 2023 14:16:25 -0500 Subject: [PATCH 1/3] docs: nested sorting --- website/pages/en/querying/graphql-api.mdx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/website/pages/en/querying/graphql-api.mdx b/website/pages/en/querying/graphql-api.mdx index 986d7bf15c35..d24092916595 100644 --- a/website/pages/en/querying/graphql-api.mdx +++ b/website/pages/en/querying/graphql-api.mdx @@ -49,6 +49,23 @@ When querying a collection, the `orderBy` parameter may be used to sort by a spe } ``` +#### Example for nested entity sorting + +Sorting on the basis of nested entities is useful if you are looking to sort entities based on child fields. + +In the following example, we sort the tokens by the name of their owner: + +```graphql +{ + tokens(orderBy: owner__name, orderDirection: asc) { + id + owner { + name + } + } +} +``` + ### Pagination When querying a collection, the `first` parameter can be used to paginate from the beginning of the collection. It is worth noting that the default sort order is by ID in ascending alphanumeric order, not by creation time. From 53091098e88e6333a5d8f201c0209a086eaa68cd Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Thu, 9 Mar 2023 15:51:27 -0500 Subject: [PATCH 2/3] 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 d24092916595..3d3485c290ce 100644 --- a/website/pages/en/querying/graphql-api.mdx +++ b/website/pages/en/querying/graphql-api.mdx @@ -51,7 +51,7 @@ When querying a collection, the `orderBy` parameter may be used to sort by a spe #### Example for nested entity sorting -Sorting on the basis of nested entities is useful if you are looking to sort entities based on child fields. +As of Graph Node [`v0.30.0`](https://github.com/graphprotocol/graph-node/releases/tag/v0.30.0) entities can be sorted on the basis of nested entities. In the following example, we sort the tokens by the name of their owner: @@ -66,6 +66,8 @@ In the following example, we sort the tokens by the name of their owner: } ``` +> Currently you can sort by one-level deep `String` or `ID` types on `@entity` and `@derivedFrom` fields. Unfortunately, [sorting by interfaces on one level-deep entities](https://github.com/graphprotocol/graph-node/pull/4058) and sorting by nested entities is not supported yet. + ### Pagination When querying a collection, the `first` parameter can be used to paginate from the beginning of the collection. It is worth noting that the default sort order is by ID in ascending alphanumeric order, not by creation time. From 0a0eea45d4516ad84f791373de939845559dd9ee Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Thu, 9 Mar 2023 16:10:08 -0500 Subject: [PATCH 3/3] clarify --- website/pages/en/querying/graphql-api.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/pages/en/querying/graphql-api.mdx b/website/pages/en/querying/graphql-api.mdx index 3d3485c290ce..8e12eafcaca7 100644 --- a/website/pages/en/querying/graphql-api.mdx +++ b/website/pages/en/querying/graphql-api.mdx @@ -66,7 +66,7 @@ In the following example, we sort the tokens by the name of their owner: } ``` -> Currently you can sort by one-level deep `String` or `ID` types on `@entity` and `@derivedFrom` fields. Unfortunately, [sorting by interfaces on one level-deep entities](https://github.com/graphprotocol/graph-node/pull/4058) and sorting by nested entities is not supported yet. +> Currently you can sort by one-level deep `String` or `ID` types on `@entity` and `@derivedFrom` fields. Unfortunately, [sorting by interfaces on one level-deep entities](https://github.com/graphprotocol/graph-node/pull/4058), sorting by fields which are arrays and nested entities is not yet supported. ### Pagination