Skip to content

Commit

Permalink
fix(GRAPHQL): fix query rewriting for multiple order on nested field (#…
Browse files Browse the repository at this point in the history
…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 8e835f1)
  • Loading branch information
JatinDev543 authored Mar 10, 2021
1 parent 48f22eb commit 856fad4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion graphql/dgraph/graphquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions graphql/resolve/query_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 856fad4

Please sign in to comment.