-
-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align total count on connection & collection segment (#4960)
- Loading branch information
1 parent
ee288d0
commit f202519
Showing
17 changed files
with
351 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 26 additions & 5 deletions
31
src/HotChocolate/Core/src/Types.CursorPagination/ConnectionPageInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,49 @@ | ||
namespace HotChocolate.Types.Pagination; | ||
|
||
/// <summary> | ||
/// Represents the connection paging page info. | ||
/// This class provides additional information about pagination in a connection. | ||
/// </summary> | ||
public class ConnectionPageInfo : IPageInfo | ||
{ | ||
/// <summary> | ||
/// Initializes <see cref="ConnectionPageInfo" />. | ||
/// </summary> | ||
/// <param name="hasNextPage"></param> | ||
/// <param name="hasPreviousPage"></param> | ||
/// <param name="startCursor"></param> | ||
/// <param name="endCursor"></param> | ||
public ConnectionPageInfo( | ||
bool hasNextPage, | ||
bool hasPreviousPage, | ||
string? startCursor, | ||
string? endCursor, | ||
int? totalCount = null) | ||
string? endCursor) | ||
{ | ||
HasNextPage = hasNextPage; | ||
HasPreviousPage = hasPreviousPage; | ||
StartCursor = startCursor; | ||
EndCursor = endCursor; | ||
TotalCount = totalCount; | ||
} | ||
|
||
/// <summary> | ||
/// <c>true</c> if there is another page after the current one. | ||
/// <c>false</c> if this page is the last page of the current data set / collection. | ||
/// </summary> | ||
public bool HasNextPage { get; } | ||
|
||
/// <summary> | ||
/// <c>true</c> if there is before this page. | ||
/// <c>false</c> if this page is the first page in the current data set / collection. | ||
/// </summary> | ||
public bool HasPreviousPage { get; } | ||
|
||
/// <summary> | ||
/// When paginating backwards, the cursor to continue. | ||
/// </summary> | ||
public string? StartCursor { get; } | ||
|
||
/// <summary> | ||
/// When paginating forwards, the cursor to continue. | ||
/// </summary> | ||
public string? EndCursor { get; } | ||
|
||
public int? TotalCount { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 22 additions & 31 deletions
53
src/HotChocolate/Core/test/Types.CursorPagination.Tests/ConnectionPageInfoTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,29 @@ | ||
using Xunit; | ||
|
||
namespace HotChocolate.Types.Pagination | ||
namespace HotChocolate.Types.Pagination; | ||
|
||
public class ConnectionPageInfoTests | ||
{ | ||
public class ConnectionPageInfoTests | ||
[InlineData(true, true, "a", "b")] | ||
[InlineData(true, false, "a", "b")] | ||
[InlineData(false, true, "a", "b")] | ||
[InlineData(true, true, null, "b")] | ||
[InlineData(true, true, "a", null)] | ||
[Theory] | ||
public void CreatePageInfo_ArgumentsArePassedCorrectly( | ||
bool hasNextPage, | ||
bool hasPreviousPage, | ||
string startCursor, | ||
string endCursor) | ||
{ | ||
[InlineData(true, true, "a", "b", null)] | ||
[InlineData(true, false, "a", "b", null)] | ||
[InlineData(false, true, "a", "b", null)] | ||
[InlineData(true, true, null, "b", null)] | ||
[InlineData(true, true, "a", null, null)] | ||
[InlineData(true, true, "a", "b", 1)] | ||
[InlineData(true, false, "a", "b", 2)] | ||
[InlineData(false, true, "a", "b", 3)] | ||
[InlineData(true, true, null, "b", 4)] | ||
[InlineData(true, true, "a", null, 5)] | ||
[Theory] | ||
public void CreatePageInfo_ArgumentsArePassedCorrectly( | ||
bool hasNextPage, bool hasPreviousPage, | ||
string startCursor, string endCursor, | ||
int? totalCount) | ||
{ | ||
// arrange | ||
// act | ||
var pageInfo = new ConnectionPageInfo( | ||
hasNextPage, hasPreviousPage, | ||
startCursor, endCursor, | ||
totalCount); | ||
// arrange | ||
// act | ||
var pageInfo = new ConnectionPageInfo(hasNextPage, hasPreviousPage, startCursor, endCursor); | ||
|
||
// assert | ||
Assert.Equal(hasNextPage, pageInfo.HasNextPage); | ||
Assert.Equal(hasPreviousPage, pageInfo.HasPreviousPage); | ||
Assert.Equal(startCursor, pageInfo.StartCursor); | ||
Assert.Equal(endCursor, pageInfo.EndCursor); | ||
Assert.Equal(totalCount, pageInfo.TotalCount); | ||
} | ||
// assert | ||
Assert.Equal(hasNextPage, pageInfo.HasNextPage); | ||
Assert.Equal(hasPreviousPage, pageInfo.HasPreviousPage); | ||
Assert.Equal(startCursor, pageInfo.StartCursor); | ||
Assert.Equal(endCursor, pageInfo.EndCursor); | ||
} | ||
} |
Oops, something went wrong.