Class GraphQlArgumentBinder
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 Summary
ConstructorDescriptionGraphQlArgumentBinder
(ConversionService conversionService) GraphQlArgumentBinder
(ConversionService conversionService, boolean fallBackOnDirectFieldAccess) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDataBinderInitializer
(Consumer<DataBinder> consumer) Deprecated, for removal: This API element is subject to removal in a future version.bind
(DataFetchingEnvironment environment, String name, ResolvableType targetType) Create and populate an Object of the given target type, from a single GraphQL argument, or from the full GraphQL arguments map.bind
(Object rawValue, boolean isOmitted, ResolvableType targetType) Variant ofbind(DataFetchingEnvironment, String, ResolvableType)
with a pre-extracted raw value to bind from.
-
Constructor Details
-
GraphQlArgumentBinder
public GraphQlArgumentBinder() -
GraphQlArgumentBinder
-
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 aDataBinder
is no longer used to bind argumentsAdd aDataBinder
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 argumentsname
- the name of an argument, ornull
to use the full maptargetType
- the type of Object to create- Returns:
- the created Object, possibly wrapped in
Optional
or inArgumentValue
, ornull
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 ofbind(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 andfalse
if it was provided, but possiblynull
targetType
- the type of Object to create- Throws:
BindException
- Since:
- 1.3.0
-
DataBinder
is no longer used to bind arguments