Skip to content

Commit 186bbe6

Browse files
fix: support ordering by terms from joined tables when using multiOrder and cursor pagination
1 parent fe67c91 commit 186bbe6

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

entgql/internal/todo/todo_test.go

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ func TestNestedConnection(t *testing.T) {
16911691
)
16921692
require.NoError(t, err)
16931693
require.Equal(t, 1, len(rsp.Group.Users.Edges))
1694-
require.Equal(t, "gaFp0wAAAAcAAAAI", rsp.Group.Users.Edges[0].Cursor)
1694+
require.Equal(t, "gaFpzwAAAAcAAAAI", rsp.Group.Users.Edges[0].Cursor)
16951695
})
16961696
}
16971697

@@ -2536,6 +2536,56 @@ func TestOrderByEdgeCount(t *testing.T) {
25362536
}
25372537
})
25382538

2539+
t.Run("MultiOrderWithPagination", func(t *testing.T) {
2540+
var (
2541+
// language=GraphQL
2542+
query = `query CategoryByTodosCount($first: Int, $after: Cursor) {
2543+
categories(
2544+
first: $first,
2545+
after: $after
2546+
orderBy: [{field: TODOS_COUNT, direction: DESC}],
2547+
) {
2548+
edges {
2549+
cursor
2550+
node {
2551+
id
2552+
text
2553+
}
2554+
}
2555+
}
2556+
}`
2557+
rsp struct {
2558+
Categories struct {
2559+
Edges []struct {
2560+
Cursor string
2561+
Node struct {
2562+
ID string
2563+
Text string
2564+
}
2565+
}
2566+
}
2567+
}
2568+
)
2569+
gqlc.MustPost(
2570+
query,
2571+
&rsp,
2572+
client.Var("first", 2),
2573+
client.Var("after", nil),
2574+
)
2575+
require.Len(t, rsp.Categories.Edges, 2)
2576+
2577+
// Do another query to get the next node after the first in our original query.
2578+
expectedNode := rsp.Categories.Edges[1].Node
2579+
gqlc.MustPost(
2580+
query,
2581+
&rsp,
2582+
client.Var("first", 1),
2583+
client.Var("after", rsp.Categories.Edges[0].Cursor),
2584+
)
2585+
require.Len(t, rsp.Categories.Edges, 1)
2586+
require.Equal(t, expectedNode.ID, rsp.Categories.Edges[0].Node.ID)
2587+
})
2588+
25392589
t.Run("NestedEdgeCountOrdering", func(t *testing.T) {
25402590
var (
25412591
// language=GraphQL

entgql/pagination.go

Lines changed: 20 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)