@@ -41,9 +41,7 @@ public class ConnectionFieldTypeVisitorTests {
4141 @ Test
4242 void paginationDataFetcher () {
4343
44- String document = BookSource .booksConnectionQuery ("" );
45-
46- TestConnectionAdapter adapter = new TestConnectionAdapter ();
44+ ListConnectionAdapter adapter = new ListConnectionAdapter ();
4745 adapter .setInitialOffset (30 );
4846 adapter .setHasNext (true );
4947
@@ -52,22 +50,22 @@ void paginationDataFetcher() {
5250 .typeDefinitionConfigurer (new ConnectionTypeDefinitionConfigurer ())
5351 .typeVisitor (ConnectionFieldTypeVisitor .create (List .of (adapter )))
5452 .toGraphQlService ()
55- .execute (TestExecutionRequest .forDocument (document ));
53+ .execute (TestExecutionRequest .forDocument (BookSource . booksConnectionQuery ( null ) ));
5654
5755 ResponseHelper .forResponse (response ).assertData (
5856 "{\" books\" :{" +
5957 "\" edges\" :[" +
60- "{\" cursor\" :\" T_30 \" ,\" node\" :{\" id\" :\" 1\" ,\" name\" :\" Nineteen Eighty-Four\" }}," +
61- "{\" cursor\" :\" T_31 \" ,\" node\" :{\" id\" :\" 2\" ,\" name\" :\" The Great Gatsby\" }}," +
62- "{\" cursor\" :\" T_32 \" ,\" node\" :{\" id\" :\" 3\" ,\" name\" :\" Catch-22\" }}," +
63- "{\" cursor\" :\" T_33 \" ,\" node\" :{\" id\" :\" 4\" ,\" name\" :\" To The Lighthouse\" }}," +
64- "{\" cursor\" :\" T_34 \" ,\" node\" :{\" id\" :\" 5\" ,\" name\" :\" Animal Farm\" }}," +
65- "{\" cursor\" :\" T_35 \" ,\" node\" :{\" id\" :\" 53\" ,\" name\" :\" Breaking Bad\" }}," +
66- "{\" cursor\" :\" T_36 \" ,\" node\" :{\" id\" :\" 42\" ,\" name\" :\" Hitchhiker's Guide to the Galaxy\" }}" +
58+ "{\" cursor\" :\" O_30 \" ,\" node\" :{\" id\" :\" 1\" ,\" name\" :\" Nineteen Eighty-Four\" }}," +
59+ "{\" cursor\" :\" O_31 \" ,\" node\" :{\" id\" :\" 2\" ,\" name\" :\" The Great Gatsby\" }}," +
60+ "{\" cursor\" :\" O_32 \" ,\" node\" :{\" id\" :\" 3\" ,\" name\" :\" Catch-22\" }}," +
61+ "{\" cursor\" :\" O_33 \" ,\" node\" :{\" id\" :\" 4\" ,\" name\" :\" To The Lighthouse\" }}," +
62+ "{\" cursor\" :\" O_34 \" ,\" node\" :{\" id\" :\" 5\" ,\" name\" :\" Animal Farm\" }}," +
63+ "{\" cursor\" :\" O_35 \" ,\" node\" :{\" id\" :\" 53\" ,\" name\" :\" Breaking Bad\" }}," +
64+ "{\" cursor\" :\" O_36 \" ,\" node\" :{\" id\" :\" 42\" ,\" name\" :\" Hitchhiker's Guide to the Galaxy\" }}" +
6765 "]," +
6866 "\" pageInfo\" :{" +
69- "\" startCursor\" :\" T_30 \" ," +
70- "\" endCursor\" :\" T_36 \" ," +
67+ "\" startCursor\" :\" O_30 \" ," +
68+ "\" endCursor\" :\" O_36 \" ," +
7169 "\" hasPreviousPage\" :true," +
7270 "\" hasNextPage\" :true}" +
7371 "}}"
@@ -77,33 +75,25 @@ void paginationDataFetcher() {
7775 @ Test // gh-707
7876 void trivialDataFetcherIsSkipped () {
7977
80- TestConnectionAdapter adapter = new TestConnectionAdapter ();
81- adapter .setInitialOffset (30 );
82- adapter .setHasNext (true );
83-
8478 Mono <ExecutionGraphQlResponse > response = GraphQlSetup .schemaResource (BookSource .paginationSchema )
8579 .dataFetcher ("Query" , "books" , new PropertyDataFetcher <>("books" ))
8680 .typeDefinitionConfigurer (new ConnectionTypeDefinitionConfigurer ())
87- .typeVisitor (ConnectionFieldTypeVisitor .create (List .of (adapter )))
81+ .typeVisitor (ConnectionFieldTypeVisitor .create (List .of (new ListConnectionAdapter () )))
8882 .toGraphQlService ()
89- .execute (TestExecutionRequest .forDocument (BookSource .booksConnectionQuery ("" )));
83+ .execute (TestExecutionRequest .forDocument (BookSource .booksConnectionQuery (null )));
9084
9185 ResponseHelper .forResponse (response ).assertData ("{\" books\" :null}" );
9286 }
9387
9488 @ Test // gh-707
9589 void nullValueTreatedAsEmptyConnection () {
9690
97- TestConnectionAdapter adapter = new TestConnectionAdapter ();
98- adapter .setInitialOffset (30 );
99- adapter .setHasNext (true );
100-
10191 Mono <ExecutionGraphQlResponse > response = GraphQlSetup .schemaResource (BookSource .paginationSchema )
10292 .dataFetcher ("Query" , "books" , environment -> null )
10393 .typeDefinitionConfigurer (new ConnectionTypeDefinitionConfigurer ())
104- .typeVisitor (ConnectionFieldTypeVisitor .create (List .of (adapter )))
94+ .typeVisitor (ConnectionFieldTypeVisitor .create (List .of (new ListConnectionAdapter () )))
10595 .toGraphQlService ()
106- .execute (TestExecutionRequest .forDocument (BookSource .booksConnectionQuery ("" )));
96+ .execute (TestExecutionRequest .forDocument (BookSource .booksConnectionQuery (null )));
10797
10898 ResponseHelper .forResponse (response ).assertData (
10999 "{\" books\" :{" +
@@ -118,7 +108,7 @@ void nullValueTreatedAsEmptyConnection() {
118108 }
119109
120110
121- private static class TestConnectionAdapter implements ConnectionAdapter {
111+ private static class ListConnectionAdapter implements ConnectionAdapter {
122112
123113 private int initialOffset = 0 ;
124114
@@ -137,9 +127,10 @@ public boolean supports(Class<?> containerType) {
137127 return Collection .class .isAssignableFrom (containerType );
138128 }
139129
130+ @ SuppressWarnings ("unchecked" )
140131 @ Override
141- public <T > Collection <T > getContent (Object container ) {
142- return (Collection <T >) container ;
132+ public <T > List <T > getContent (Object container ) {
133+ return (List <T >) container ;
143134 }
144135
145136 @ Override
@@ -154,7 +145,7 @@ public boolean hasNext(Object container) {
154145
155146 @ Override
156147 public String cursorAt (Object container , int index ) {
157- return "T_ " + (this .initialOffset + index );
148+ return "O_ " + (this .initialOffset + index );
158149 }
159150
160151 }
0 commit comments