34
34
import reactor .core .publisher .Mono ;
35
35
36
36
import org .springframework .core .io .Resource ;
37
+ import org .springframework .graphql .Book ;
37
38
import org .springframework .graphql .BookSource ;
38
39
import org .springframework .graphql .ExecutionGraphQlResponse ;
39
40
import org .springframework .graphql .GraphQlSetup ;
@@ -51,7 +52,7 @@ public class ConnectionFieldTypeVisitorTests {
51
52
52
53
53
54
@ Test
54
- void paginationDataFetcher () {
55
+ void paginatedTypeIsAdapted () {
55
56
56
57
ListConnectionAdapter adapter = new ListConnectionAdapter ();
57
58
adapter .setInitialOffset (30 );
@@ -83,6 +84,39 @@ void paginationDataFetcher() {
83
84
);
84
85
}
85
86
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
+
86
120
@ Test // gh-707
87
121
void nullValueTreatedAsEmptyConnection () {
88
122
@@ -226,4 +260,14 @@ public String cursorAt(Object container, int index) {
226
260
227
261
}
228
262
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
+
229
273
}
0 commit comments