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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceContract to customize the mapping of GraphQL argument names to Object properties.static final classContainer of configuration settings forGraphQlArgumentBinder. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.GraphQlArgumentBinder(@Nullable ConversionService conversionService) Deprecated, for removal: This API element is subject to removal in a future version.GraphQlArgumentBinder(@Nullable ConversionService service, boolean fallBackOnDirectFieldAccess) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofGraphQlArgumentBinder(Options) -
Method Summary
Modifier and TypeMethodDescription@Nullable Objectbind(graphql.schema.DataFetchingEnvironment environment, @Nullable 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.@Nullable Objectbind(@Nullable 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()Default constructor. -
GraphQlArgumentBinder
@Deprecated(since="2.0", forRemoval=true) public GraphQlArgumentBinder(@Nullable ConversionService conversionService) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofGraphQlArgumentBinder(Options)Constructor with additional flag for direct field access support.- Parameters:
conversionService- the service to use
-
GraphQlArgumentBinder
@Deprecated(since="2.0", forRemoval=true) public GraphQlArgumentBinder(@Nullable ConversionService service, boolean fallBackOnDirectFieldAccess) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofGraphQlArgumentBinder(Options)Constructor with additional flag for direct field access support.- Parameters:
service- the service to usefallBackOnDirectFieldAccess- whether to fall back on direct field access
-
GraphQlArgumentBinder
-
-
Method Details
-
bind
public @Nullable Object bind(graphql.schema.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, ornullto use the full maptargetType- the type of Object to create- Returns:
- the created Object, possibly wrapped in
Optionalor inArgumentValue, ornullif there is no value - Throws:
BindException- containing one or more accumulated errors from matching and/or converting arguments to the target Object
-
bind
public @Nullable 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-trueif the argument was omitted from the input andfalseif it was provided, but possiblynulltargetType- the type of Object to create- Throws:
BindException- Since:
- 1.3.0
-
GraphQlArgumentBinder(Options)