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)

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.
  • Loading branch information
JatinDev543 authored Mar 8, 2021
1 parent 98aaf00 commit 8e835f1
Show file tree
Hide file tree
Showing 2 changed files with 24 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 @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions graphql/resolve/query_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down

0 comments on commit 8e835f1

Please sign in to comment.