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 Nov 25, 2023
1 parent 58d4e15 commit a2af310
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
52 changes: 51 additions & 1 deletion entgql/internal/todo/todo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ func TestNestedConnection(t *testing.T) {
)
require.NoError(t, err)
require.Equal(t, 1, len(rsp.Group.Users.Edges))
require.Equal(t, "gaFp0wAAAAcAAAAI", rsp.Group.Users.Edges[0].Cursor)
require.Equal(t, "gaFpzwAAAAcAAAAI", rsp.Group.Users.Edges[0].Cursor)
})
}

Expand Down Expand Up @@ -2536,6 +2536,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 a2af310

Please sign in to comment.