From 6d5e76e14e7e505c9147f910db796e7a2915be8b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 23 Mar 2023 13:18:27 +0000 Subject: [PATCH] Polish "Configure support for GraphQL pagination and sorting" See gh-34677 --- .../graphql/GraphQlAutoConfiguration.java | 3 ++- .../graphql/GraphQlAutoConfigurationTests.java | 14 +++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfiguration.java index 6f735c3fd4..37a2b97c40 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfiguration.java @@ -51,6 +51,7 @@ import org.springframework.graphql.data.method.annotation.support.AnnotatedContr import org.springframework.graphql.data.pagination.ConnectionFieldTypeVisitor; import org.springframework.graphql.data.pagination.CursorEncoder; import org.springframework.graphql.data.pagination.CursorStrategy; +import org.springframework.graphql.data.pagination.EncodingCursorStrategy; import org.springframework.graphql.data.query.ScrollPositionCursorStrategy; import org.springframework.graphql.data.query.SliceConnectionAdapter; import org.springframework.graphql.data.query.WindowConnectionAdapter; @@ -170,7 +171,7 @@ public class GraphQlAutoConfiguration { @Bean @ConditionalOnMissingBean - CursorStrategy cursorStrategy() { + EncodingCursorStrategy cursorStrategy() { return CursorStrategy.withEncoder(new ScrollPositionCursorStrategy(), CursorEncoder.base64()); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfigurationTests.java index b39901b974..0ba2700d05 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfigurationTests.java @@ -44,7 +44,6 @@ import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.ClassPathResource; import org.springframework.graphql.ExecutionGraphQlService; import org.springframework.graphql.data.method.annotation.support.AnnotatedControllerConfigurer; -import org.springframework.graphql.data.pagination.CursorStrategy; import org.springframework.graphql.data.pagination.EncodingCursorStrategy; import org.springframework.graphql.execution.BatchLoaderRegistry; import org.springframework.graphql.execution.DataFetcherExceptionResolver; @@ -65,14 +64,11 @@ class GraphQlAutoConfigurationTests { @Test void shouldContributeDefaultBeans() { - this.contextRunner.run((context) -> { - assertThat(context).hasSingleBean(GraphQlSource.class) - .hasSingleBean(BatchLoaderRegistry.class) - .hasSingleBean(ExecutionGraphQlService.class) - .hasSingleBean(AnnotatedControllerConfigurer.class) - .hasSingleBean(CursorStrategy.class); - assertThat(context.getBean(CursorStrategy.class)).isInstanceOf(EncodingCursorStrategy.class); - }); + this.contextRunner.run((context) -> assertThat(context).hasSingleBean(GraphQlSource.class) + .hasSingleBean(BatchLoaderRegistry.class) + .hasSingleBean(ExecutionGraphQlService.class) + .hasSingleBean(AnnotatedControllerConfigurer.class) + .hasSingleBean(EncodingCursorStrategy.class)); } @Test