@@ -41,9 +41,7 @@ public class ConnectionFieldTypeVisitorTests {
41
41
@ Test
42
42
void paginationDataFetcher () {
43
43
44
- String document = BookSource .booksConnectionQuery ("" );
45
-
46
- TestConnectionAdapter adapter = new TestConnectionAdapter ();
44
+ ListConnectionAdapter adapter = new ListConnectionAdapter ();
47
45
adapter .setInitialOffset (30 );
48
46
adapter .setHasNext (true );
49
47
@@ -52,22 +50,22 @@ void paginationDataFetcher() {
52
50
.typeDefinitionConfigurer (new ConnectionTypeDefinitionConfigurer ())
53
51
.typeVisitor (ConnectionFieldTypeVisitor .create (List .of (adapter )))
54
52
.toGraphQlService ()
55
- .execute (TestExecutionRequest .forDocument (document ));
53
+ .execute (TestExecutionRequest .forDocument (BookSource . booksConnectionQuery ( null ) ));
56
54
57
55
ResponseHelper .forResponse (response ).assertData (
58
56
"{\" books\" :{" +
59
57
"\" 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\" }}" +
67
65
"]," +
68
66
"\" pageInfo\" :{" +
69
- "\" startCursor\" :\" T_30 \" ," +
70
- "\" endCursor\" :\" T_36 \" ," +
67
+ "\" startCursor\" :\" O_30 \" ," +
68
+ "\" endCursor\" :\" O_36 \" ," +
71
69
"\" hasPreviousPage\" :true," +
72
70
"\" hasNextPage\" :true}" +
73
71
"}}"
@@ -77,33 +75,25 @@ void paginationDataFetcher() {
77
75
@ Test // gh-707
78
76
void trivialDataFetcherIsSkipped () {
79
77
80
- TestConnectionAdapter adapter = new TestConnectionAdapter ();
81
- adapter .setInitialOffset (30 );
82
- adapter .setHasNext (true );
83
-
84
78
Mono <ExecutionGraphQlResponse > response = GraphQlSetup .schemaResource (BookSource .paginationSchema )
85
79
.dataFetcher ("Query" , "books" , new PropertyDataFetcher <>("books" ))
86
80
.typeDefinitionConfigurer (new ConnectionTypeDefinitionConfigurer ())
87
- .typeVisitor (ConnectionFieldTypeVisitor .create (List .of (adapter )))
81
+ .typeVisitor (ConnectionFieldTypeVisitor .create (List .of (new ListConnectionAdapter () )))
88
82
.toGraphQlService ()
89
- .execute (TestExecutionRequest .forDocument (BookSource .booksConnectionQuery ("" )));
83
+ .execute (TestExecutionRequest .forDocument (BookSource .booksConnectionQuery (null )));
90
84
91
85
ResponseHelper .forResponse (response ).assertData ("{\" books\" :null}" );
92
86
}
93
87
94
88
@ Test // gh-707
95
89
void nullValueTreatedAsEmptyConnection () {
96
90
97
- TestConnectionAdapter adapter = new TestConnectionAdapter ();
98
- adapter .setInitialOffset (30 );
99
- adapter .setHasNext (true );
100
-
101
91
Mono <ExecutionGraphQlResponse > response = GraphQlSetup .schemaResource (BookSource .paginationSchema )
102
92
.dataFetcher ("Query" , "books" , environment -> null )
103
93
.typeDefinitionConfigurer (new ConnectionTypeDefinitionConfigurer ())
104
- .typeVisitor (ConnectionFieldTypeVisitor .create (List .of (adapter )))
94
+ .typeVisitor (ConnectionFieldTypeVisitor .create (List .of (new ListConnectionAdapter () )))
105
95
.toGraphQlService ()
106
- .execute (TestExecutionRequest .forDocument (BookSource .booksConnectionQuery ("" )));
96
+ .execute (TestExecutionRequest .forDocument (BookSource .booksConnectionQuery (null )));
107
97
108
98
ResponseHelper .forResponse (response ).assertData (
109
99
"{\" books\" :{" +
@@ -118,7 +108,7 @@ void nullValueTreatedAsEmptyConnection() {
118
108
}
119
109
120
110
121
- private static class TestConnectionAdapter implements ConnectionAdapter {
111
+ private static class ListConnectionAdapter implements ConnectionAdapter {
122
112
123
113
private int initialOffset = 0 ;
124
114
@@ -137,9 +127,10 @@ public boolean supports(Class<?> containerType) {
137
127
return Collection .class .isAssignableFrom (containerType );
138
128
}
139
129
130
+ @ SuppressWarnings ("unchecked" )
140
131
@ 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 ;
143
134
}
144
135
145
136
@ Override
@@ -154,7 +145,7 @@ public boolean hasNext(Object container) {
154
145
155
146
@ Override
156
147
public String cursorAt (Object container , int index ) {
157
- return "T_ " + (this .initialOffset + index );
148
+ return "O_ " + (this .initialOffset + index );
158
149
}
159
150
160
151
}
0 commit comments