Skip to content

Commit

Permalink
entgql: added test case for non-relay edge
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Aug 30, 2022
1 parent 354f833 commit 6ebd2e1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions entgql/internal/todo/todo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ func TestNestedConnection(t *testing.T) {
bulkU[i] = ec.User.Create().SetName(fmt.Sprintf("user-%d", i)).AddGroups(groups[:len(groups)-i]...)
}
users := ec.User.CreateBulk(bulkU...).SaveX(ctx)
users[0].Update().AddFriends(users[1:]...).SaveX(ctx)

t.Run("TotalCount", func(t *testing.T) {
var (
Expand All @@ -1325,6 +1326,9 @@ func TestNestedConnection(t *testing.T) {
groups {
totalCount
}
friends {
name
}
}
}
}
Expand All @@ -1338,6 +1342,9 @@ func TestNestedConnection(t *testing.T) {
Groups struct {
TotalCount int
}
Friends []struct {
Name string
}
}
}
}
Expand All @@ -1348,16 +1355,17 @@ func TestNestedConnection(t *testing.T) {
require.NoError(t, err)
// One query for loading all users, and one for getting the groups of each user.
// The totalCount of the root query can be inferred from the length of the user edges.
require.EqualValues(t, 2, count.value())
require.EqualValues(t, 3, count.value())
require.Equal(t, 10, rsp.Users.TotalCount)
require.Equal(t, 9, len(rsp.Users.Edges[0].Node.Friends))

for n := 1; n <= 10; n++ {
count.reset()
err = gqlc.Post(query, &rsp, client.Var("first", n))
require.NoError(t, err)
// Two queries for getting the users and their totalCount.
// And another one for getting the totalCount of each user.
require.EqualValues(t, 3, count.value())
require.EqualValues(t, 4, count.value())
require.Equal(t, 10, rsp.Users.TotalCount)
for i, e := range rsp.Users.Edges {
require.Equal(t, users[i].Name, e.Node.Name)
Expand Down

0 comments on commit 6ebd2e1

Please sign in to comment.