Class GraphQlArgumentBinder

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

public class GraphQlArgumentBinder extends Object
Bind a GraphQL argument, or the full arguments map, onto a target object.

Binding is performed by mapping argument values to a primary data constructor of the target object, or by using a default constructor and mapping argument values to its properties. This is applied recursively.

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

    • GraphQlArgumentBinder

      public GraphQlArgumentBinder()
    • GraphQlArgumentBinder

      public GraphQlArgumentBinder(@Nullable ConversionService conversionService)
  • Method Details

    • addDataBinderInitializer

      public void addDataBinderInitializer(Consumer<DataBinder> dataBinderInitializer)
      Add a DataBinder consumer that initializes the binder instance before the binding process.
      Parameters:
      dataBinderInitializer - the data binder initializer
      Since:
      1.0.1
    • bind

      @Nullable public Object bind(DataFetchingEnvironment environment, @Nullable String argumentName, ResolvableType targetType) throws BindException
      Bind a single argument, or the full arguments map, onto an object of the given target type.
      Parameters:
      environment - for access to the arguments
      argumentName - the name of the argument to bind, or null to use the full arguments map
      targetType - the type of Object to create
      Returns:
      the created Object, possibly null
      Throws:
      BindException - in case of binding issues such as conversion errors, mismatches between the source and the target object structure, and so on. Binding issues are accumulated as field errors where the field of each error is the argument path where the issue occurred.