|
18 | 18 |
|
19 | 19 | import java.util.Collection;
|
20 | 20 | import java.util.List;
|
| 21 | +import java.util.function.Consumer; |
21 | 22 |
|
| 23 | +import graphql.execution.DataFetcherResult; |
22 | 24 | import graphql.schema.DataFetcher;
|
23 | 25 | import graphql.schema.FieldCoordinates;
|
24 | 26 | import graphql.schema.GraphQLFieldDefinition;
|
@@ -52,36 +54,41 @@ public class ConnectionFieldTypeVisitorTests {
|
52 | 54 |
|
53 | 55 |
|
54 | 56 | @Test
|
55 |
| - void paginatedTypeIsAdapted() { |
56 |
| - |
57 |
| - ListConnectionAdapter adapter = new ListConnectionAdapter(); |
58 |
| - adapter.setInitialOffset(30); |
59 |
| - adapter.setHasNext(true); |
60 |
| - |
61 |
| - Mono<ExecutionGraphQlResponse> response = GraphQlSetup.schemaResource(BookSource.paginationSchema) |
62 |
| - .dataFetcher("Query", "books", env -> BookSource.books()) |
63 |
| - .connectionSupport(adapter) |
64 |
| - .toGraphQlService() |
65 |
| - .execute(BookSource.booksConnectionQuery(null)); |
66 |
| - |
67 |
| - ResponseHelper.forResponse(response).assertData( |
68 |
| - "{\"books\":{" + |
69 |
| - "\"edges\":[" + |
70 |
| - "{\"cursor\":\"O_30\",\"node\":{\"id\":\"1\",\"name\":\"Nineteen Eighty-Four\"}}," + |
71 |
| - "{\"cursor\":\"O_31\",\"node\":{\"id\":\"2\",\"name\":\"The Great Gatsby\"}}," + |
72 |
| - "{\"cursor\":\"O_32\",\"node\":{\"id\":\"3\",\"name\":\"Catch-22\"}}," + |
73 |
| - "{\"cursor\":\"O_33\",\"node\":{\"id\":\"4\",\"name\":\"To The Lighthouse\"}}," + |
74 |
| - "{\"cursor\":\"O_34\",\"node\":{\"id\":\"5\",\"name\":\"Animal Farm\"}}," + |
75 |
| - "{\"cursor\":\"O_35\",\"node\":{\"id\":\"53\",\"name\":\"Breaking Bad\"}}," + |
76 |
| - "{\"cursor\":\"O_36\",\"node\":{\"id\":\"42\",\"name\":\"Hitchhiker's Guide to the Galaxy\"}}" + |
77 |
| - "]," + |
78 |
| - "\"pageInfo\":{" + |
79 |
| - "\"startCursor\":\"O_30\"," + |
80 |
| - "\"endCursor\":\"O_36\"," + |
81 |
| - "\"hasPreviousPage\":true," + |
82 |
| - "\"hasNextPage\":true}" + |
83 |
| - "}}" |
84 |
| - ); |
| 57 | + void adaptPaginatedType() { |
| 58 | + |
| 59 | + Consumer<DataFetcher<Object>> testConsumer = booksDataFetcher -> { |
| 60 | + ListConnectionAdapter adapter = new ListConnectionAdapter(); |
| 61 | + adapter.setInitialOffset(30); |
| 62 | + adapter.setHasNext(true); |
| 63 | + |
| 64 | + Mono<ExecutionGraphQlResponse> response = GraphQlSetup.schemaResource(BookSource.paginationSchema) |
| 65 | + .dataFetcher("Query", "books", booksDataFetcher) |
| 66 | + .connectionSupport(adapter) |
| 67 | + .toGraphQlService() |
| 68 | + .execute(BookSource.booksConnectionQuery(null)); |
| 69 | + |
| 70 | + ResponseHelper.forResponse(response).assertData( |
| 71 | + "{\"books\":{" + |
| 72 | + "\"edges\":[" + |
| 73 | + "{\"cursor\":\"O_30\",\"node\":{\"id\":\"1\",\"name\":\"Nineteen Eighty-Four\"}}," + |
| 74 | + "{\"cursor\":\"O_31\",\"node\":{\"id\":\"2\",\"name\":\"The Great Gatsby\"}}," + |
| 75 | + "{\"cursor\":\"O_32\",\"node\":{\"id\":\"3\",\"name\":\"Catch-22\"}}," + |
| 76 | + "{\"cursor\":\"O_33\",\"node\":{\"id\":\"4\",\"name\":\"To The Lighthouse\"}}," + |
| 77 | + "{\"cursor\":\"O_34\",\"node\":{\"id\":\"5\",\"name\":\"Animal Farm\"}}," + |
| 78 | + "{\"cursor\":\"O_35\",\"node\":{\"id\":\"53\",\"name\":\"Breaking Bad\"}}," + |
| 79 | + "{\"cursor\":\"O_36\",\"node\":{\"id\":\"42\",\"name\":\"Hitchhiker's Guide to the Galaxy\"}}" + |
| 80 | + "]," + |
| 81 | + "\"pageInfo\":{" + |
| 82 | + "\"startCursor\":\"O_30\"," + |
| 83 | + "\"endCursor\":\"O_36\"," + |
| 84 | + "\"hasPreviousPage\":true," + |
| 85 | + "\"hasNextPage\":true}" + |
| 86 | + "}}" |
| 87 | + ); |
| 88 | + }; |
| 89 | + |
| 90 | + testConsumer.accept(env -> BookSource.books()); |
| 91 | + testConsumer.accept(env -> DataFetcherResult.newResult().data(BookSource.books()).build()); |
85 | 92 | }
|
86 | 93 |
|
87 | 94 | @Test // gh-709
|
|
0 commit comments