From 856fad483133081416a6fb940d5bc9ed2a684da7 Mon Sep 17 00:00:00 2001 From: Jatin Dev <64803093+JatinDevDG@users.noreply.github.com> Date: Wed, 10 Mar 2021 16:36:32 +0530 Subject: [PATCH] fix(GRAPHQL): fix query rewriting for multiple order on nested field (#7523) (#7536) * fix(GRAPHQL): fix query rewriting for multiple order on nested field. (#7523) We were not adding the , in-between multiple orders in query rewriting for the nested field. For example the order given in this filter posts(filter: { title: { anyofterms: "GraphQL" } }, order: { asc: numLikes, then: { desc: title } }, first: 10, offset: 10) got written to below dgraph statement Author.posts : Author.posts @filter(anyofterms(Post.title, "GraphQL")) (orderasc: Post.numLikesorderdesc: Post.title, first: 10, offset: 10) where there is no comma between two orders. We have fixed it in this PR. (cherry picked from commit 8e835f111d0fb5edf24ffde8b8456ed46bd82c08) --- graphql/dgraph/graphquery.go | 2 +- graphql/resolve/query_test.yaml | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/graphql/dgraph/graphquery.go b/graphql/dgraph/graphquery.go index 5f5e1983857..f7cd9d9065b 100644 --- a/graphql/dgraph/graphquery.go +++ b/graphql/dgraph/graphquery.go @@ -217,7 +217,7 @@ func writeOrderAndPage(b *strings.Builder, query *gql.GraphQuery, root bool) { var wroteOrder, wroteFirst bool for _, ord := range query.Order { - if root { + if root || wroteOrder { x.Check2(b.WriteString(", ")) } if ord.Desc { diff --git a/graphql/resolve/query_test.yaml b/graphql/resolve/query_test.yaml index b7ae68ca705..e40a2aaa507 100644 --- a/graphql/resolve/query_test.yaml +++ b/graphql/resolve/query_test.yaml @@ -1263,6 +1263,28 @@ } } +- + name: "Deep filter with multiple order, first and offset" + gqlquery: | + query { + queryAuthor { + name + posts(filter: { title: { anyofterms: "GraphQL" } }, order: { asc: numLikes, then: { desc: title } }, first: 10, offset: 10) { + title + } + } + } + dgquery: |- + query { + queryAuthor(func: type(Author)) { + name : Author.name + posts : Author.posts @filter(anyofterms(Post.title, "GraphQL")) (orderasc: Post.numLikes, orderdesc: Post.title, first: 10, offset: 10) { + title : Post.title + dgraph.uid : uid + } + dgraph.uid : uid + } + } - name: "All Float filters work"