@@ -132,63 +132,61 @@ public void addFormatterRegistrar(FormatterRegistrar registrar) {
132132 registrar .registerFormatters (this .conversionService );
133133 }
134134
135- /**
136- * Configure the {@link ConversionService} used for binding handler arguments.
137- * @deprecated in favor of using {@link #addFormatterRegistrar(FormatterRegistrar)}
138- * to customize the built-in ConversionService instance.
139- */
140- @ Deprecated
141- public void setConversionService (ConversionService conversionService ) {
142- Assert .isInstanceOf (FormattingConversionService .class , conversionService );
143- this .conversionService = (FormattingConversionService ) conversionService ;
144- }
145-
146135 @ Override
147136 public void setApplicationContext (ApplicationContext applicationContext ) {
148137 this .applicationContext = applicationContext ;
149138 }
150139
151- protected final ApplicationContext obtainApplicationContext () {
152- Assert .state (this .applicationContext != null , "No ApplicationContext" );
153- return this .applicationContext ;
154- }
155-
156140
157141 @ Override
158142 public void afterPropertiesSet () {
159- this .argumentResolvers = new HandlerMethodArgumentResolverComposite ();
143+
144+ this .argumentResolvers = initArgumentResolvers ();
145+
146+ if (beanValidationPresent ) {
147+ this .validator = HandlerMethodInputValidatorFactory .create (obtainApplicationContext ());
148+ }
149+ }
150+
151+ private HandlerMethodArgumentResolverComposite initArgumentResolvers () {
152+
153+ HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite ();
160154
161155 // Annotation based
162156 if (springDataPresent ) {
163157 // Must be ahead of ArgumentMethodArgumentResolver
164- this . argumentResolvers .addResolver (new ProjectedPayloadMethodArgumentResolver (obtainApplicationContext ()));
158+ resolvers .addResolver (new ProjectedPayloadMethodArgumentResolver (obtainApplicationContext ()));
165159 }
166- this . argumentResolvers .addResolver (new ArgumentMapMethodArgumentResolver ());
160+ resolvers .addResolver (new ArgumentMapMethodArgumentResolver ());
167161 GraphQlArgumentBinder argumentBinder = new GraphQlArgumentBinder (this .conversionService );
168- this . argumentResolvers .addResolver (new ArgumentMethodArgumentResolver (argumentBinder ));
169- this . argumentResolvers .addResolver (new ArgumentsMethodArgumentResolver (argumentBinder ));
170- this . argumentResolvers .addResolver (new ContextValueMethodArgumentResolver ());
162+ resolvers .addResolver (new ArgumentMethodArgumentResolver (argumentBinder ));
163+ resolvers .addResolver (new ArgumentsMethodArgumentResolver (argumentBinder ));
164+ resolvers .addResolver (new ContextValueMethodArgumentResolver ());
171165
172166 // Type based
173- this . argumentResolvers .addResolver (new DataFetchingEnvironmentMethodArgumentResolver ());
174- this . argumentResolvers .addResolver (new DataLoaderMethodArgumentResolver ());
167+ resolvers .addResolver (new DataFetchingEnvironmentMethodArgumentResolver ());
168+ resolvers .addResolver (new DataLoaderMethodArgumentResolver ());
175169 if (springSecurityPresent ) {
176- this . argumentResolvers .addResolver (new PrincipalMethodArgumentResolver ());
170+ resolvers .addResolver (new PrincipalMethodArgumentResolver ());
177171 BeanResolver beanResolver = new BeanFactoryResolver (obtainApplicationContext ());
178- this . argumentResolvers .addResolver (new AuthenticationPrincipalArgumentResolver (beanResolver ));
172+ resolvers .addResolver (new AuthenticationPrincipalArgumentResolver (beanResolver ));
179173 }
180174 if (KotlinDetector .isKotlinPresent ()) {
181- this . argumentResolvers .addResolver (new ContinuationHandlerMethodArgumentResolver ());
175+ resolvers .addResolver (new ContinuationHandlerMethodArgumentResolver ());
182176 }
183177
184- // This works as a fallback, after other resolvers
185- this . argumentResolvers .addResolver (new SourceMethodArgumentResolver ());
178+ // This works as a fallback, after all other resolvers
179+ resolvers .addResolver (new SourceMethodArgumentResolver ());
186180
187- if (beanValidationPresent ) {
188- this .validator = HandlerMethodInputValidatorFactory .create (obtainApplicationContext ());
189- }
181+ return resolvers ;
190182 }
191183
184+ protected final ApplicationContext obtainApplicationContext () {
185+ Assert .state (this .applicationContext != null , "No ApplicationContext" );
186+ return this .applicationContext ;
187+ }
188+
189+
192190 @ Override
193191 public void configure (RuntimeWiring .Builder runtimeWiringBuilder ) {
194192 Assert .state (this .argumentResolvers != null , "`argumentResolvers` is not initialized" );
@@ -251,8 +249,8 @@ private Collection<MappingInfo> findHandlerMethods(Object handler, @Nullable Cla
251249 }
252250
253251 Class <?> userClass = ClassUtils .getUserClass (handlerClass );
254- Map <Method , MappingInfo > map =
255- MethodIntrospector . selectMethods ( userClass , (Method method ) -> getMappingInfo (method , handler , userClass ));
252+ Map <Method , MappingInfo > map = MethodIntrospector . selectMethods (
253+ userClass , (Method method ) -> getMappingInfo (method , handler , userClass ));
256254
257255 Collection <MappingInfo > mappingInfos = map .values ();
258256
@@ -330,10 +328,10 @@ private MappingInfo getMappingInfo(Method method, Object handler, Class<?> handl
330328 }
331329
332330 private HandlerMethod createHandlerMethod (Method method , Object handler , Class <?> handlerType ) {
333- Method invocableMethod = AopUtils .selectInvocableMethod (method , handlerType );
331+ Method theMethod = AopUtils .selectInvocableMethod (method , handlerType );
334332 return (handler instanceof String ?
335- new HandlerMethod ((String ) handler , obtainApplicationContext ().getAutowireCapableBeanFactory (), invocableMethod ) :
336- new HandlerMethod (handler , invocableMethod ));
333+ new HandlerMethod ((String ) handler , obtainApplicationContext ().getAutowireCapableBeanFactory (), theMethod ) :
334+ new HandlerMethod (handler , theMethod ));
337335 }
338336
339337 private String formatMappings (Class <?> handlerType , Collection <MappingInfo > infos ) {
@@ -389,12 +387,11 @@ public void configure(GraphQLCodeRegistry.Builder codeRegistryBuilder) {
389387 configure (wiringBuilder );
390388 RuntimeWiring runtimeWiring = wiringBuilder .build ();
391389
392- runtimeWiring .getDataFetchers ().forEach ((typeName , dataFetcherMap ) -> {
393- dataFetcherMap .forEach ((key , value ) -> {
394- FieldCoordinates coordinates = FieldCoordinates .coordinates (typeName , key );
395- codeRegistryBuilder .dataFetcher (coordinates , (DataFetcher <?>) value );
396- });
397- });
390+ runtimeWiring .getDataFetchers ().forEach ((typeName , dataFetcherMap ) ->
391+ dataFetcherMap .forEach ((key , value ) -> {
392+ FieldCoordinates coordinates = FieldCoordinates .coordinates (typeName , key );
393+ codeRegistryBuilder .dataFetcher (coordinates , (DataFetcher <?>) value );
394+ }));
398395 }
399396
400397
@@ -416,6 +413,7 @@ public FieldCoordinates getCoordinates() {
416413 return this .coordinates ;
417414 }
418415
416+ @ SuppressWarnings ("BooleanMethodIsAlwaysInverted" )
419417 public boolean isBatchMapping () {
420418 return this .batchMapping ;
421419 }
@@ -445,8 +443,10 @@ static class SchemaMappingDataFetcher implements DataFetcher<Object> {
445443
446444 private final boolean subscription ;
447445
448- public SchemaMappingDataFetcher (MappingInfo info , HandlerMethodArgumentResolverComposite resolvers ,
446+ public SchemaMappingDataFetcher (
447+ MappingInfo info , HandlerMethodArgumentResolverComposite resolvers ,
449448 @ Nullable HandlerMethodInputValidator validator ) {
449+
450450 this .info = info ;
451451 this .argumentResolvers = resolvers ;
452452 this .validator = validator ;
@@ -471,7 +471,11 @@ public HandlerMethod getHandlerMethod() {
471471 @ Override
472472 @ SuppressWarnings ("ConstantConditions" )
473473 public Object get (DataFetchingEnvironment environment ) throws Exception {
474- return new DataFetcherHandlerMethod (getHandlerMethod (), this .argumentResolvers , this .validator , this .subscription ).invoke (environment );
474+
475+ DataFetcherHandlerMethod handlerMethod = new DataFetcherHandlerMethod (
476+ getHandlerMethod (), this .argumentResolvers , this .validator , this .subscription );
477+
478+ return handlerMethod .invoke (environment );
475479 }
476480 }
477481
0 commit comments