Class GraphQlArgumentBinder

java.lang.Object
org.springframework.graphql.data.GraphQlArgumentBinder

public class GraphQlArgumentBinder extends Object
Binder that instantiates and populates a target Object to reflect the complete structure of the GraphQL arguments input map.

The input map is navigated recursively to create the full structure of the target type. Objects in the target type are created either through a primary, data constructor, in which case arguments are matched to constructor parameters by name, or through the default constructor, in which case arguments are matched to properties. Scalar values are converted, if necessary, through a ConversionService.

The binder does not stop at the first error, but rather accumulates as many errors as it can in a BindingResult. At the end it raises a BindException that contains all recorded errors along with the path at which each error occurred.

The binder supports Optional as a wrapper around any Object or scalar value in the target Object structure. In addition, it also supports ArgumentValue as a wrapper that indicates whether a given input argument was omitted rather than set to the "null" literal.

Since:
1.0.0
Author:
Brian Clozel, Rossen Stoyanchev
  • Constructor Details

    • GraphQlArgumentBinder

      public GraphQlArgumentBinder()
    • GraphQlArgumentBinder

      public GraphQlArgumentBinder(@Nullable ConversionService conversionService)
    • GraphQlArgumentBinder

      public GraphQlArgumentBinder(@Nullable ConversionService conversionService, boolean fallBackOnDirectFieldAccess)
  • Method Details

    • addDataBinderInitializer

      @Deprecated(since="1.1.0", forRemoval=true) public void addDataBinderInitializer(Consumer<DataBinder> consumer)
      Deprecated, for removal: This API element is subject to removal in a future version.
      this property is deprecated, ignored, and should not be necessary as a DataBinder is no longer used to bind arguments
      Add a DataBinder consumer that initializes the binder instance before the binding process.
      Parameters:
      consumer - the data binder initializer
      Since:
      1.0.1
    • bind

      @Nullable public Object bind(DataFetchingEnvironment environment, @Nullable String name, ResolvableType targetType) throws BindException
      Create and populate an Object of the given target type, from a single GraphQL argument, or from the full GraphQL arguments map.
      Parameters:
      environment - for access to the arguments
      name - the name of an argument, or null to use the full map
      targetType - the type of Object to create
      Returns:
      the created Object, possibly wrapped in Optional or in ArgumentValue, or null if there is no value
      Throws:
      BindException - containing one or more accumulated errors from matching and/or converting arguments to the target Object
    • bind

      @Nullable public Object bind(@Nullable Object rawValue, boolean isOmitted, ResolvableType targetType) throws BindException
      Variant of bind(DataFetchingEnvironment, String, ResolvableType) with a pre-extracted raw value to bind from.
      Parameters:
      rawValue - the raw argument value (Collection, Map, or scalar)
      isOmitted - true if the argument was omitted from the input and false if it was provided, but possibly null
      targetType - the type of Object to create
      Throws:
      BindException
      Since:
      1.3.0