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 newProjectedPayloadMethodArgumentResolver
using the given context. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
createProjection
(Class<?> targetType, Object rawValue) Protected method to create the projection.protected org.springframework.data.projection.SpelAwareProxyProjectionFactory
Return underlying projection factory used by the resolver.resolveArgument
(MethodParameter parameter, DataFetchingEnvironment environment) Resolve a method parameter to a value.boolean
supportsParameter
(MethodParameter parameter) Whether this resolver supports the givenMethodParameter
.
-
Constructor Details
-
ProjectedPayloadMethodArgumentResolver
Create a newProjectedPayloadMethodArgumentResolver
using the given context.- Parameters:
applicationContext
- theApplicationContext
to 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:HandlerMethodArgumentResolver
Whether this resolver supports the givenMethodParameter
.- Specified by:
supportsParameter
in interfaceHandlerMethodArgumentResolver
- Parameters:
parameter
- the method parameter to check for support
-
resolveArgument
public Object resolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) throws Exception Description copied from interface:HandlerMethodArgumentResolver
Resolve a method parameter to a value.- Specified by:
resolveArgument
in 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
null
if not resolved; the value may also be aMono
if 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 viaArgument
or the map of arguments- Returns:
- the created project instance
-