File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,4 +77,13 @@ public override IReadOnlyList<PageEdge<TNode>>? Edges
7777 /// </summary>
7878 [ GraphQLDescription ( "Identifies the total count of items in the connection." ) ]
7979 public int TotalCount => _page . TotalCount ?? - 1 ;
80+
81+ /// <summary>
82+ /// Converts a <see cref="Page{TNode}"/> to a <see cref="PageConnection{TNode}"/>.
83+ /// </summary>
84+ /// <param name="page">
85+ /// The page to convert.
86+ /// </param>
87+ public static implicit operator PageConnection < TNode > ( Page < TNode > page )
88+ => new ( page ) ;
8089}
Original file line number Diff line number Diff line change 1+ using GreenDonut . Data ;
2+
3+ namespace HotChocolate . Types . Pagination ;
4+
5+ public class PageConnectionTests
6+ {
7+ [ Fact ]
8+ public void ImplicitConversion_Should_WrapPage_When_ConvertingPageToConnection ( )
9+ {
10+ // arrange
11+ var page = Page < string > . Create (
12+ [ "a" , "b" , "c" ] ,
13+ hasNextPage : true ,
14+ hasPreviousPage : false ,
15+ item => item ,
16+ totalCount : 10 ) ;
17+
18+ // act
19+ PageConnection < string > connection = page ;
20+
21+ // assert
22+ Assert . Same ( page , connection . Nodes ) ;
23+ Assert . Equal ( 10 , connection . TotalCount ) ;
24+ Assert . Equal ( 3 , connection . Edges ! . Count ) ;
25+ Assert . True ( connection . PageInfo . HasNextPage ) ;
26+ }
27+
28+ [ Fact ]
29+ public void ImplicitConversion_Should_ThrowArgumentNullException_When_PageIsNull ( )
30+ {
31+ // arrange
32+ Page < string > ? page = null ;
33+
34+ // act
35+ PageConnection < string > Convert ( ) => page ! ;
36+
37+ // assert
38+ Assert . Throws < ArgumentNullException > ( Convert ) ;
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments