From cb2504916cded5873acb9258b19fdc0281999026 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 1/3] 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 | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 40 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..5c28aec372c 100644 --- a/graphql/resolve/query_test.yaml +++ b/graphql/resolve/query_test.yaml @@ -1263,6 +1263,45 @@ } } +- + 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: | + query { + queryAuthor(filter:{ reputation: { gt: 123456789.113 } }) { + name + } + } + dgquery: |- + query { + queryAuthor(func: type(Author)) @filter(gt(Author.reputation, "1.23456789113e+08")) { + Author.name : Author.name + dgraph.uid : uid + } + } + - name: "All Float filters work" From 4f1134133bea54cebc7bb5872122507573f11c9f Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Tue, 9 Mar 2021 21:26:21 +0530 Subject: [PATCH 2/3] fix test --- graphql/resolve/query_test.yaml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/graphql/resolve/query_test.yaml b/graphql/resolve/query_test.yaml index 5c28aec372c..4a9fa113b05 100644 --- a/graphql/resolve/query_test.yaml +++ b/graphql/resolve/query_test.yaml @@ -1286,23 +1286,6 @@ } } -- - name: "Float with large exponentiation" - gqlquery: | - query { - queryAuthor(filter:{ reputation: { gt: 123456789.113 } }) { - name - } - } - dgquery: |- - query { - queryAuthor(func: type(Author)) @filter(gt(Author.reputation, "1.23456789113e+08")) { - Author.name : Author.name - dgraph.uid : uid - } - } - - - name: "All Float filters work" gqlquery: | From 056145e6c23c89b1758dbb9af4d78720f17b808c Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Tue, 9 Mar 2021 22:25:21 +0530 Subject: [PATCH 3/3] fixed test --- graphql/resolve/query_test.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/graphql/resolve/query_test.yaml b/graphql/resolve/query_test.yaml index 4a9fa113b05..e40a2aaa507 100644 --- a/graphql/resolve/query_test.yaml +++ b/graphql/resolve/query_test.yaml @@ -1277,9 +1277,9 @@ 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 + 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