diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java index 07386a78..cab7f4ae 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java @@ -132,63 +132,61 @@ public class AnnotatedControllerConfigurer registrar.registerFormatters(this.conversionService); } - /** - * Configure the {@link ConversionService} used for binding handler arguments. - * @deprecated in favor of using {@link #addFormatterRegistrar(FormatterRegistrar)} - * to customize the built-in ConversionService instance. - */ - @Deprecated - public void setConversionService(ConversionService conversionService) { - Assert.isInstanceOf(FormattingConversionService.class, conversionService); - this.conversionService = (FormattingConversionService) conversionService; - } - @Override public void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; } + + @Override + public void afterPropertiesSet() { + + this.argumentResolvers = initArgumentResolvers(); + + if (beanValidationPresent) { + this.validator = HandlerMethodInputValidatorFactory.create(obtainApplicationContext()); + } + } + + private HandlerMethodArgumentResolverComposite initArgumentResolvers() { + + HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite(); + + // Annotation based + if (springDataPresent) { + // Must be ahead of ArgumentMethodArgumentResolver + resolvers.addResolver(new ProjectedPayloadMethodArgumentResolver(obtainApplicationContext())); + } + resolvers.addResolver(new ArgumentMapMethodArgumentResolver()); + GraphQlArgumentBinder argumentBinder = new GraphQlArgumentBinder(this.conversionService); + resolvers.addResolver(new ArgumentMethodArgumentResolver(argumentBinder)); + resolvers.addResolver(new ArgumentsMethodArgumentResolver(argumentBinder)); + resolvers.addResolver(new ContextValueMethodArgumentResolver()); + + // Type based + resolvers.addResolver(new DataFetchingEnvironmentMethodArgumentResolver()); + resolvers.addResolver(new DataLoaderMethodArgumentResolver()); + if (springSecurityPresent) { + resolvers.addResolver(new PrincipalMethodArgumentResolver()); + BeanResolver beanResolver = new BeanFactoryResolver(obtainApplicationContext()); + resolvers.addResolver(new AuthenticationPrincipalArgumentResolver(beanResolver)); + } + if (KotlinDetector.isKotlinPresent()) { + resolvers.addResolver(new ContinuationHandlerMethodArgumentResolver()); + } + + // This works as a fallback, after all other resolvers + resolvers.addResolver(new SourceMethodArgumentResolver()); + + return resolvers; + } + protected final ApplicationContext obtainApplicationContext() { Assert.state(this.applicationContext != null, "No ApplicationContext"); return this.applicationContext; } - @Override - public void afterPropertiesSet() { - this.argumentResolvers = new HandlerMethodArgumentResolverComposite(); - - // Annotation based - if (springDataPresent) { - // Must be ahead of ArgumentMethodArgumentResolver - this.argumentResolvers.addResolver(new ProjectedPayloadMethodArgumentResolver(obtainApplicationContext())); - } - this.argumentResolvers.addResolver(new ArgumentMapMethodArgumentResolver()); - GraphQlArgumentBinder argumentBinder = new GraphQlArgumentBinder(this.conversionService); - this.argumentResolvers.addResolver(new ArgumentMethodArgumentResolver(argumentBinder)); - this.argumentResolvers.addResolver(new ArgumentsMethodArgumentResolver(argumentBinder)); - this.argumentResolvers.addResolver(new ContextValueMethodArgumentResolver()); - - // Type based - this.argumentResolvers.addResolver(new DataFetchingEnvironmentMethodArgumentResolver()); - this.argumentResolvers.addResolver(new DataLoaderMethodArgumentResolver()); - if (springSecurityPresent) { - this.argumentResolvers.addResolver(new PrincipalMethodArgumentResolver()); - BeanResolver beanResolver = new BeanFactoryResolver(obtainApplicationContext()); - this.argumentResolvers.addResolver(new AuthenticationPrincipalArgumentResolver(beanResolver)); - } - if (KotlinDetector.isKotlinPresent()) { - this.argumentResolvers.addResolver(new ContinuationHandlerMethodArgumentResolver()); - } - - // This works as a fallback, after other resolvers - this.argumentResolvers.addResolver(new SourceMethodArgumentResolver()); - - if (beanValidationPresent) { - this.validator = HandlerMethodInputValidatorFactory.create(obtainApplicationContext()); - } - } - @Override public void configure(RuntimeWiring.Builder runtimeWiringBuilder) { Assert.state(this.argumentResolvers != null, "`argumentResolvers` is not initialized"); @@ -251,8 +249,8 @@ public class AnnotatedControllerConfigurer } Class userClass = ClassUtils.getUserClass(handlerClass); - Map map = - MethodIntrospector.selectMethods(userClass, (Method method) -> getMappingInfo(method, handler, userClass)); + Map map = MethodIntrospector.selectMethods( + userClass, (Method method) -> getMappingInfo(method, handler, userClass)); Collection mappingInfos = map.values(); @@ -330,10 +328,10 @@ public class AnnotatedControllerConfigurer } private HandlerMethod createHandlerMethod(Method method, Object handler, Class handlerType) { - Method invocableMethod = AopUtils.selectInvocableMethod(method, handlerType); + Method theMethod = AopUtils.selectInvocableMethod(method, handlerType); return (handler instanceof String ? - new HandlerMethod((String) handler, obtainApplicationContext().getAutowireCapableBeanFactory(), invocableMethod) : - new HandlerMethod(handler, invocableMethod)); + new HandlerMethod((String) handler, obtainApplicationContext().getAutowireCapableBeanFactory(), theMethod) : + new HandlerMethod(handler, theMethod)); } private String formatMappings(Class handlerType, Collection infos) { @@ -389,12 +387,11 @@ public class AnnotatedControllerConfigurer configure(wiringBuilder); RuntimeWiring runtimeWiring = wiringBuilder.build(); - runtimeWiring.getDataFetchers().forEach((typeName, dataFetcherMap) -> { - dataFetcherMap.forEach((key, value) -> { - FieldCoordinates coordinates = FieldCoordinates.coordinates(typeName, key); - codeRegistryBuilder.dataFetcher(coordinates, (DataFetcher) value); - }); - }); + runtimeWiring.getDataFetchers().forEach((typeName, dataFetcherMap) -> + dataFetcherMap.forEach((key, value) -> { + FieldCoordinates coordinates = FieldCoordinates.coordinates(typeName, key); + codeRegistryBuilder.dataFetcher(coordinates, (DataFetcher) value); + })); } @@ -416,6 +413,7 @@ public class AnnotatedControllerConfigurer return this.coordinates; } + @SuppressWarnings("BooleanMethodIsAlwaysInverted") public boolean isBatchMapping() { return this.batchMapping; } @@ -445,8 +443,10 @@ public class AnnotatedControllerConfigurer private final boolean subscription; - public SchemaMappingDataFetcher(MappingInfo info, HandlerMethodArgumentResolverComposite resolvers, + public SchemaMappingDataFetcher( + MappingInfo info, HandlerMethodArgumentResolverComposite resolvers, @Nullable HandlerMethodInputValidator validator) { + this.info = info; this.argumentResolvers = resolvers; this.validator = validator; @@ -471,7 +471,11 @@ public class AnnotatedControllerConfigurer @Override @SuppressWarnings("ConstantConditions") public Object get(DataFetchingEnvironment environment) throws Exception { - return new DataFetcherHandlerMethod(getHandlerMethod(), this.argumentResolvers, this.validator, this.subscription).invoke(environment); + + DataFetcherHandlerMethod handlerMethod = new DataFetcherHandlerMethod( + getHandlerMethod(), this.argumentResolvers, this.validator, this.subscription); + + return handlerMethod.invoke(environment); } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlHttpHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlHttpHandler.java index cf9703fd..5b051e6e 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlHttpHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlHttpHandler.java @@ -44,10 +44,10 @@ public class GraphQlHttpHandler { private static final Log logger = LogFactory.getLog(GraphQlHttpHandler.class); private static final ParameterizedTypeReference> MAP_PARAMETERIZED_TYPE_REF = - new ParameterizedTypeReference>() { - }; + new ParameterizedTypeReference>() {}; - private static final List SUPPORTED_MEDIA_TYPES = Arrays.asList(MediaType.APPLICATION_GRAPHQL, MediaType.APPLICATION_JSON); + private static final List SUPPORTED_MEDIA_TYPES = + Arrays.asList(MediaType.APPLICATION_GRAPHQL, MediaType.APPLICATION_JSON); private final WebGraphQlHandler graphQlHandler; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandler.java index ab3282d7..3b12b3de 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandler.java @@ -53,10 +53,10 @@ public class GraphQlHttpHandler { private static final Log logger = LogFactory.getLog(GraphQlHttpHandler.class); private static final ParameterizedTypeReference> MAP_PARAMETERIZED_TYPE_REF = - new ParameterizedTypeReference>() { - }; + new ParameterizedTypeReference>() {}; - private static final List SUPPORTED_MEDIA_TYPES = Arrays.asList(MediaType.APPLICATION_GRAPHQL, MediaType.APPLICATION_JSON); + private static final List SUPPORTED_MEDIA_TYPES = + Arrays.asList(MediaType.APPLICATION_GRAPHQL, MediaType.APPLICATION_JSON); private final IdGenerator idGenerator = new AlternativeJdkIdGenerator();