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 Details

  • Method Details

    • getProjectionFactory

      protected org.springframework.data.projection.SpelAwareProxyProjectionFactory getProjectionFactory()
      Return underlying projection factory used by the resolver.
      Since:
      1.1.1
    • supportsParameter

      public boolean supportsParameter(MethodParameter parameter)
      Description copied from interface: HandlerMethodArgumentResolver
      Whether this resolver supports the given MethodParameter.
      Specified by:
      supportsParameter in interface HandlerMethodArgumentResolver
      Parameters:
      parameter - the method parameter to check for support
    • resolveArgument

      public @Nullable Object resolveArgument(MethodParameter parameter, graphql.schema.DataFetchingEnvironment environment) throws Exception
      Description copied from interface: HandlerMethodArgumentResolver
      Resolve a method parameter to a value.
      Specified by:
      resolveArgument in interface HandlerMethodArgumentResolver
      Parameters:
      parameter - the method parameter to resolve. This parameter must have previously checked via HandlerMethodArgumentResolver.supportsParameter(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 a Mono if it requires asynchronous resolution.
      Throws:
      Exception - in case of errors with the preparation of argument values
    • createProjection

      protected Object createProjection(Class<?> targetType, Object rawValue)
      Protected method to create the projection. The default implementation delegates to the underlying projectionFactory.
      Parameters:
      targetType - the type to create
      rawValue - a specific argument (if named via Argument or the map of arguments
      Returns:
      the created project instance