From 8e835f111d0fb5edf24ffde8b8456ed46bd82c08 Mon Sep 17 00:00:00 2001 From: Jatin Dev <64803093+JatinDevDG@users.noreply.github.com> Date: Mon, 8 Mar 2021 20:06:15 +0530 Subject: [PATCH] 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. --- graphql/dgraph/graphquery.go | 2 +- graphql/resolve/query_test.yaml | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/graphql/dgraph/graphquery.go b/graphql/dgraph/graphquery.go index 94aaac698b6..ea3a34fc589 100644 --- a/graphql/dgraph/graphquery.go +++ b/graphql/dgraph/graphquery.go @@ -219,7 +219,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 6eb80324bf1..264ba9be54f 100644 --- a/graphql/resolve/query_test.yaml +++ b/graphql/resolve/query_test.yaml @@ -1351,6 +1351,29 @@ } } +- + 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)) { + Author.name : Author.name + Author.posts : Author.posts @filter(anyofterms(Post.title, "GraphQL")) (orderasc: Post.numLikes, orderdesc: Post.title, first: 10, offset: 10) { + Post.title : Post.title + dgraph.uid : uid + } + dgraph.uid : uid + } + } + - name: "Float with large exponentiation" gqlquery: |