Class ProjectedPayloadMethodArgumentResolver
java.lang.Object
org.springframework.graphql.data.method.annotation.support.ProjectedPayloadMethodArgumentResolver
- All Implemented Interfaces:
HandlerMethodArgumentResolver
public class ProjectedPayloadMethodArgumentResolver
extends Object
implements HandlerMethodArgumentResolver
Resolver for a method parameter that is an interface annotated with
@ProjectedPayload.
By default, the projection is prepared by using the complete
arguments map as its source.
Add @Argument with a name, if you to prepare it by using a
specific argument value instead as its source.
An @ProjectedPayload interface has accessor methods. In a closed
projection, getter methods access underlying properties directly. In an open
projection, getter methods make use of the @Value annotation to
evaluate SpEL expressions against the underlying target object.
For example:
@ProjectedPayload
interface BookProjection {
String getName();
@Value("#{target.author + ' ' + target.name}")
String getAuthorAndName();
}
- Since:
- 1.0.0
- Author:
- Mark Paluch, Rossen Stoyanchev
-
Constructor Summary
ConstructorsConstructorDescriptionProjectedPayloadMethodArgumentResolver(ApplicationContext applicationContext) Create a newProjectedPayloadMethodArgumentResolverusing the given context. -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectcreateProjection(Class<?> targetType, Object rawValue) Protected method to create the projection.protected org.springframework.data.projection.SpelAwareProxyProjectionFactoryReturn underlying projection factory used by the resolver.resolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) Resolve a method parameter to a value.booleansupportsParameter(MethodParameter parameter) Whether this resolver supports the givenMethodParameter.
-
Constructor Details
-
ProjectedPayloadMethodArgumentResolver
Create a newProjectedPayloadMethodArgumentResolverusing the given context.- Parameters:
applicationContext- theApplicationContextto use for bean lookup and class loading
-
-
Method Details
-
getProjectionFactory
protected org.springframework.data.projection.SpelAwareProxyProjectionFactory getProjectionFactory()Return underlying projection factory used by the resolver.- Since:
- 1.1.1
-
supportsParameter
Description copied from interface:HandlerMethodArgumentResolverWhether this resolver supports the givenMethodParameter.- Specified by:
supportsParameterin interfaceHandlerMethodArgumentResolver
-
resolveArgument
public Object resolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) throws Exception Description copied from interface:HandlerMethodArgumentResolverResolve a method parameter to a value.- Specified by:
resolveArgumentin interfaceHandlerMethodArgumentResolver- Parameters:
parameter- the method parameter to resolve. This parameter must have previously checked viaHandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter).environment- the environment to use to resolve the value- Returns:
- the resolved value, which may be
nullif not resolved; the value may also be aMonoif it requires asynchronous resolution. - Throws:
Exception- in case of errors with the preparation of argument values
-
createProjection
Protected method to create the projection. The default implementation delegates to the underlyingprojectionFactory.- Parameters:
targetType- the type to createrawValue- a specific argument (if named viaArgumentor the map of arguments- Returns:
- the created project instance
-