3434import reactor .core .publisher .Mono ;
3535
3636import org .springframework .core .io .Resource ;
37+ import org .springframework .graphql .Book ;
3738import org .springframework .graphql .BookSource ;
3839import org .springframework .graphql .ExecutionGraphQlResponse ;
3940import org .springframework .graphql .GraphQlSetup ;
@@ -51,7 +52,7 @@ public class ConnectionFieldTypeVisitorTests {
5152
5253
5354 @ Test
54- void paginationDataFetcher () {
55+ void paginatedTypeIsAdapted () {
5556
5657 ListConnectionAdapter adapter = new ListConnectionAdapter ();
5758 adapter .setInitialOffset (30 );
@@ -83,6 +84,39 @@ void paginationDataFetcher() {
8384 );
8485 }
8586
87+ @ Test // gh-709
88+ void customConnectionTypeIsPassedThrough () {
89+
90+ List <MyEdge <Book >> edges = BookSource .books ().stream ().map (book -> new MyEdge <>("0_" + book .getId (), book )).toList ();
91+ MyPageInfo pageInfo = new MyPageInfo (edges .get (0 ).cursor (), edges .get (edges .size () - 1 ).cursor , true , true );
92+ MyConnection <Book > connection = new MyConnection <>(edges , pageInfo );
93+
94+ Mono <ExecutionGraphQlResponse > response = GraphQlSetup .schemaResource (BookSource .paginationSchema )
95+ .dataFetcher ("Query" , "books" , env -> connection )
96+ .connectionSupport (new ListConnectionAdapter ())
97+ .toGraphQlService ()
98+ .execute (BookSource .booksConnectionQuery (null ));
99+
100+ ResponseHelper .forResponse (response ).assertData (
101+ "{\" books\" :{" +
102+ "\" edges\" :[" +
103+ "{\" cursor\" :\" 0_1\" ,\" node\" :{\" id\" :\" 1\" ,\" name\" :\" Nineteen Eighty-Four\" }}," +
104+ "{\" cursor\" :\" 0_2\" ,\" node\" :{\" id\" :\" 2\" ,\" name\" :\" The Great Gatsby\" }}," +
105+ "{\" cursor\" :\" 0_3\" ,\" node\" :{\" id\" :\" 3\" ,\" name\" :\" Catch-22\" }}," +
106+ "{\" cursor\" :\" 0_4\" ,\" node\" :{\" id\" :\" 4\" ,\" name\" :\" To The Lighthouse\" }}," +
107+ "{\" cursor\" :\" 0_5\" ,\" node\" :{\" id\" :\" 5\" ,\" name\" :\" Animal Farm\" }}," +
108+ "{\" cursor\" :\" 0_53\" ,\" node\" :{\" id\" :\" 53\" ,\" name\" :\" Breaking Bad\" }}," +
109+ "{\" cursor\" :\" 0_42\" ,\" node\" :{\" id\" :\" 42\" ,\" name\" :\" Hitchhiker's Guide to the Galaxy\" }}" +
110+ "]," +
111+ "\" pageInfo\" :{" +
112+ "\" startCursor\" :\" 0_1\" ," +
113+ "\" endCursor\" :\" 0_42\" ," +
114+ "\" hasPreviousPage\" :true," +
115+ "\" hasNextPage\" :true}" +
116+ "}}"
117+ );
118+ }
119+
86120 @ Test // gh-707
87121 void nullValueTreatedAsEmptyConnection () {
88122
@@ -226,4 +260,14 @@ public String cursorAt(Object container, int index) {
226260
227261 }
228262
263+
264+ private record MyConnection <T >(List <MyEdge <T >> edges , MyPageInfo pageInfo ) {
265+ }
266+
267+ private record MyEdge <T >(String cursor , T node ) {
268+ }
269+
270+ private record MyPageInfo (String startCursor , String endCursor , boolean hasPreviousPage , boolean hasNextPage ) {
271+ }
272+
229273}
0 commit comments