Polishing in ConnectionFieldTypeVisitorTests
This commit is contained in:
@@ -61,7 +61,7 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
public final class ConnectionFieldTypeVisitor extends GraphQLTypeVisitorStub {
|
public final class ConnectionFieldTypeVisitor extends GraphQLTypeVisitorStub {
|
||||||
|
|
||||||
private static Log logger = LogFactory.getLog(ConnectionFieldTypeVisitor.class);
|
private static final Log logger = LogFactory.getLog(ConnectionFieldTypeVisitor.class);
|
||||||
|
|
||||||
|
|
||||||
private final ConnectionAdapter adapter;
|
private final ConnectionAdapter adapter;
|
||||||
|
|||||||
@@ -41,9 +41,7 @@ public class ConnectionFieldTypeVisitorTests {
|
|||||||
@Test
|
@Test
|
||||||
void paginationDataFetcher() {
|
void paginationDataFetcher() {
|
||||||
|
|
||||||
String document = BookSource.booksConnectionQuery("");
|
ListConnectionAdapter adapter = new ListConnectionAdapter();
|
||||||
|
|
||||||
TestConnectionAdapter adapter = new TestConnectionAdapter();
|
|
||||||
adapter.setInitialOffset(30);
|
adapter.setInitialOffset(30);
|
||||||
adapter.setHasNext(true);
|
adapter.setHasNext(true);
|
||||||
|
|
||||||
@@ -52,22 +50,22 @@ public class ConnectionFieldTypeVisitorTests {
|
|||||||
.typeDefinitionConfigurer(new ConnectionTypeDefinitionConfigurer())
|
.typeDefinitionConfigurer(new ConnectionTypeDefinitionConfigurer())
|
||||||
.typeVisitor(ConnectionFieldTypeVisitor.create(List.of(adapter)))
|
.typeVisitor(ConnectionFieldTypeVisitor.create(List.of(adapter)))
|
||||||
.toGraphQlService()
|
.toGraphQlService()
|
||||||
.execute(TestExecutionRequest.forDocument(document));
|
.execute(TestExecutionRequest.forDocument(BookSource.booksConnectionQuery(null)));
|
||||||
|
|
||||||
ResponseHelper.forResponse(response).assertData(
|
ResponseHelper.forResponse(response).assertData(
|
||||||
"{\"books\":{" +
|
"{\"books\":{" +
|
||||||
"\"edges\":[" +
|
"\"edges\":[" +
|
||||||
"{\"cursor\":\"T_30\",\"node\":{\"id\":\"1\",\"name\":\"Nineteen Eighty-Four\"}}," +
|
"{\"cursor\":\"O_30\",\"node\":{\"id\":\"1\",\"name\":\"Nineteen Eighty-Four\"}}," +
|
||||||
"{\"cursor\":\"T_31\",\"node\":{\"id\":\"2\",\"name\":\"The Great Gatsby\"}}," +
|
"{\"cursor\":\"O_31\",\"node\":{\"id\":\"2\",\"name\":\"The Great Gatsby\"}}," +
|
||||||
"{\"cursor\":\"T_32\",\"node\":{\"id\":\"3\",\"name\":\"Catch-22\"}}," +
|
"{\"cursor\":\"O_32\",\"node\":{\"id\":\"3\",\"name\":\"Catch-22\"}}," +
|
||||||
"{\"cursor\":\"T_33\",\"node\":{\"id\":\"4\",\"name\":\"To The Lighthouse\"}}," +
|
"{\"cursor\":\"O_33\",\"node\":{\"id\":\"4\",\"name\":\"To The Lighthouse\"}}," +
|
||||||
"{\"cursor\":\"T_34\",\"node\":{\"id\":\"5\",\"name\":\"Animal Farm\"}}," +
|
"{\"cursor\":\"O_34\",\"node\":{\"id\":\"5\",\"name\":\"Animal Farm\"}}," +
|
||||||
"{\"cursor\":\"T_35\",\"node\":{\"id\":\"53\",\"name\":\"Breaking Bad\"}}," +
|
"{\"cursor\":\"O_35\",\"node\":{\"id\":\"53\",\"name\":\"Breaking Bad\"}}," +
|
||||||
"{\"cursor\":\"T_36\",\"node\":{\"id\":\"42\",\"name\":\"Hitchhiker's Guide to the Galaxy\"}}" +
|
"{\"cursor\":\"O_36\",\"node\":{\"id\":\"42\",\"name\":\"Hitchhiker's Guide to the Galaxy\"}}" +
|
||||||
"]," +
|
"]," +
|
||||||
"\"pageInfo\":{" +
|
"\"pageInfo\":{" +
|
||||||
"\"startCursor\":\"T_30\"," +
|
"\"startCursor\":\"O_30\"," +
|
||||||
"\"endCursor\":\"T_36\"," +
|
"\"endCursor\":\"O_36\"," +
|
||||||
"\"hasPreviousPage\":true," +
|
"\"hasPreviousPage\":true," +
|
||||||
"\"hasNextPage\":true}" +
|
"\"hasNextPage\":true}" +
|
||||||
"}}"
|
"}}"
|
||||||
@@ -77,16 +75,12 @@ public class ConnectionFieldTypeVisitorTests {
|
|||||||
@Test // gh-707
|
@Test // gh-707
|
||||||
void trivialDataFetcherIsSkipped() {
|
void trivialDataFetcherIsSkipped() {
|
||||||
|
|
||||||
TestConnectionAdapter adapter = new TestConnectionAdapter();
|
|
||||||
adapter.setInitialOffset(30);
|
|
||||||
adapter.setHasNext(true);
|
|
||||||
|
|
||||||
Mono<ExecutionGraphQlResponse> response = GraphQlSetup.schemaResource(BookSource.paginationSchema)
|
Mono<ExecutionGraphQlResponse> response = GraphQlSetup.schemaResource(BookSource.paginationSchema)
|
||||||
.dataFetcher("Query", "books", new PropertyDataFetcher<>("books"))
|
.dataFetcher("Query", "books", new PropertyDataFetcher<>("books"))
|
||||||
.typeDefinitionConfigurer(new ConnectionTypeDefinitionConfigurer())
|
.typeDefinitionConfigurer(new ConnectionTypeDefinitionConfigurer())
|
||||||
.typeVisitor(ConnectionFieldTypeVisitor.create(List.of(adapter)))
|
.typeVisitor(ConnectionFieldTypeVisitor.create(List.of(new ListConnectionAdapter())))
|
||||||
.toGraphQlService()
|
.toGraphQlService()
|
||||||
.execute(TestExecutionRequest.forDocument(BookSource.booksConnectionQuery("")));
|
.execute(TestExecutionRequest.forDocument(BookSource.booksConnectionQuery(null)));
|
||||||
|
|
||||||
ResponseHelper.forResponse(response).assertData("{\"books\":null}");
|
ResponseHelper.forResponse(response).assertData("{\"books\":null}");
|
||||||
}
|
}
|
||||||
@@ -94,16 +88,12 @@ public class ConnectionFieldTypeVisitorTests {
|
|||||||
@Test // gh-707
|
@Test // gh-707
|
||||||
void nullValueTreatedAsEmptyConnection() {
|
void nullValueTreatedAsEmptyConnection() {
|
||||||
|
|
||||||
TestConnectionAdapter adapter = new TestConnectionAdapter();
|
|
||||||
adapter.setInitialOffset(30);
|
|
||||||
adapter.setHasNext(true);
|
|
||||||
|
|
||||||
Mono<ExecutionGraphQlResponse> response = GraphQlSetup.schemaResource(BookSource.paginationSchema)
|
Mono<ExecutionGraphQlResponse> response = GraphQlSetup.schemaResource(BookSource.paginationSchema)
|
||||||
.dataFetcher("Query", "books", environment -> null)
|
.dataFetcher("Query", "books", environment -> null)
|
||||||
.typeDefinitionConfigurer(new ConnectionTypeDefinitionConfigurer())
|
.typeDefinitionConfigurer(new ConnectionTypeDefinitionConfigurer())
|
||||||
.typeVisitor(ConnectionFieldTypeVisitor.create(List.of(adapter)))
|
.typeVisitor(ConnectionFieldTypeVisitor.create(List.of(new ListConnectionAdapter())))
|
||||||
.toGraphQlService()
|
.toGraphQlService()
|
||||||
.execute(TestExecutionRequest.forDocument(BookSource.booksConnectionQuery("")));
|
.execute(TestExecutionRequest.forDocument(BookSource.booksConnectionQuery(null)));
|
||||||
|
|
||||||
ResponseHelper.forResponse(response).assertData(
|
ResponseHelper.forResponse(response).assertData(
|
||||||
"{\"books\":{" +
|
"{\"books\":{" +
|
||||||
@@ -118,7 +108,7 @@ public class ConnectionFieldTypeVisitorTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TestConnectionAdapter implements ConnectionAdapter {
|
private static class ListConnectionAdapter implements ConnectionAdapter {
|
||||||
|
|
||||||
private int initialOffset = 0;
|
private int initialOffset = 0;
|
||||||
|
|
||||||
@@ -137,9 +127,10 @@ public class ConnectionFieldTypeVisitorTests {
|
|||||||
return Collection.class.isAssignableFrom(containerType);
|
return Collection.class.isAssignableFrom(containerType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T> Collection<T> getContent(Object container) {
|
public <T> List<T> getContent(Object container) {
|
||||||
return (Collection<T>) container;
|
return (List<T>) container;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -154,7 +145,7 @@ public class ConnectionFieldTypeVisitorTests {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String cursorAt(Object container, int index) {
|
public String cursorAt(Object container, int index) {
|
||||||
return "T_" + (this.initialOffset + index);
|
return "O_" + (this.initialOffset + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user