Skip to content

Commit

Permalink
fix: support ordering by terms from joined tables when using multiOrd…
Browse files Browse the repository at this point in the history
…er and cursor pagination
  • Loading branch information
michaelcaulley committed Sep 10, 2024
1 parent 316dcd5 commit 4b5c676
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
50 changes: 50 additions & 0 deletions entgql/internal/todo/todo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2698,6 +2698,56 @@ func TestOrderByEdgeCount(t *testing.T) {
}
})

t.Run("MultiOrderWithPagination", func(t *testing.T) {
var (
// language=GraphQL
query = `query CategoryByTodosCount($first: Int, $after: Cursor) {
categories(
first: $first,
after: $after
orderBy: [{field: TODOS_COUNT, direction: DESC}],
) {
edges {
cursor
node {
id
text
}
}
}
}`
rsp struct {
Categories struct {
Edges []struct {
Cursor string
Node struct {
ID string
Text string
}
}
}
}
)
gqlc.MustPost(
query,
&rsp,
client.Var("first", 2),
client.Var("after", nil),
)
require.Len(t, rsp.Categories.Edges, 2)

// Do another query to get the next node after the first in our original query.
expectedNode := rsp.Categories.Edges[1].Node
gqlc.MustPost(
query,
&rsp,
client.Var("first", 1),
client.Var("after", rsp.Categories.Edges[0].Cursor),
)
require.Len(t, rsp.Categories.Edges, 1)
require.Equal(t, expectedNode.ID, rsp.Categories.Edges[0].Node.ID)
})

t.Run("NestedEdgeCountOrdering", func(t *testing.T) {
var (
// language=GraphQL
Expand Down
24 changes: 20 additions & 4 deletions entgql/pagination.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4b5c676

Please sign in to comment.