Package org.springframework.graphql.data
Class GraphQlArgumentBinder
java.lang.Object
org.springframework.graphql.data.GraphQlArgumentBinder
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDataBinderInitializer
(Consumer<DataBinder> dataBinderInitializer) Add aDataBinder
consumer that initializes the binder instance before the binding process.bind
(DataFetchingEnvironment environment, String argumentName, ResolvableType targetType) Bind a single argument, or the full arguments map, onto an object of the given target type.
-
Constructor Details
-
GraphQlArgumentBinder
public GraphQlArgumentBinder() -
GraphQlArgumentBinder
-
-
Method Details
-
addDataBinderInitializer
Add aDataBinder
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 argumentsargumentName
- the name of the argument to bind, ornull
to use the full arguments maptargetType
- 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 asfield errors
where thefield
of each error is the argument path where the issue occurred.
-