Polishing contribution
Closes gh-202
This commit is contained in:
@@ -87,6 +87,7 @@ public class AnnotatedControllerConfigurer
|
||||
private final static boolean springDataPresent = ClassUtils.isPresent(
|
||||
"org.springframework.data.projection.SpelAwareProxyProjectionFactory",
|
||||
AnnotatedControllerConfigurer.class.getClassLoader());
|
||||
|
||||
private final static boolean springSecurityPresent = ClassUtils.isPresent(
|
||||
"org.springframework.security.core.context.SecurityContext",
|
||||
AnnotatedControllerConfigurer.class.getClassLoader());
|
||||
@@ -121,6 +122,7 @@ public class AnnotatedControllerConfigurer
|
||||
public void afterPropertiesSet() {
|
||||
this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
|
||||
if (springDataPresent) {
|
||||
// This must be ahead of ArgumentMethodArgumentResolver
|
||||
this.argumentResolvers.addResolver(new ProjectedPayloadMethodArgumentResolver());
|
||||
}
|
||||
this.argumentResolvers.addResolver(new ArgumentMapMethodArgumentResolver());
|
||||
|
||||
@@ -30,14 +30,16 @@ import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
|
||||
import org.springframework.graphql.data.method.annotation.Argument;
|
||||
|
||||
/**
|
||||
* Resolver to obtain a {@link ProjectedPayload @ProjectedPayload}
|
||||
* for {@link DataFetchingEnvironment#getArguments()}.
|
||||
* Resolver to obtain an {@link ProjectedPayload @ProjectedPayload},
|
||||
* either based on the complete {@link DataFetchingEnvironment#getArguments()}
|
||||
* map, or based on a specific argument within the map when the method
|
||||
* parameter is annotated with {@code @Argument}.
|
||||
*
|
||||
* <p>Projected payloads consist of the projection interface and accessor methods.
|
||||
* Projections can be closed or open projections. Closed projections use interface
|
||||
* getter methods to access underlying properties directly. Open projection methods
|
||||
* make use of the {@code @Value} annotation to evaluate SpEL expressions against the
|
||||
* underlying {@code target} object.
|
||||
* <p>Projected payloads consist of the projection interface and accessor
|
||||
* methods. Projections can be closed or open projections. Closed projections
|
||||
* use interface getter methods to access underlying properties directly.
|
||||
* Open projection methods make use of the {@code @Value} annotation to
|
||||
* evaluate SpEL expressions against the underlying {@code target} object.
|
||||
*
|
||||
* <p>For example:
|
||||
* <pre class="code">
|
||||
@@ -62,6 +64,17 @@ public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgu
|
||||
private final SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
|
||||
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
this.projectionFactory.setBeanFactory(beanFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.projectionFactory.setBeanClassLoader(classLoader);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
Class<?> type = parameter.getParameterType();
|
||||
@@ -88,13 +101,4 @@ public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgu
|
||||
return this.projectionFactory.createProjection(projectionType, projectionSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
this.projectionFactory.setBeanFactory(beanFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.projectionFactory.setBeanClassLoader(classLoader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class SchemaMappingInvocationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryWithProjectedArgument() {
|
||||
void queryWithProjectionOnArgumentsMap() {
|
||||
String query = "{ " +
|
||||
" booksByProjectedArguments(author:\"Orwell\") { " +
|
||||
" id" +
|
||||
@@ -116,7 +116,7 @@ public class SchemaMappingInvocationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void booksByProjectedCriteria() {
|
||||
void queryWithProjectionOnNamedArgument() {
|
||||
String query = "{ " +
|
||||
" booksByProjectedCriteria(criteria: {author:\"Orwell\"}) { " +
|
||||
" id" +
|
||||
|
||||
Reference in New Issue
Block a user