Automattic\WooCommerce\Api\Infrastructure
ResolverHelpers::create_input
Invoke a factory callable, catching InvalidArgumentException and converting it to a client-visible GraphQL error.
Used to wrap construction of unrolled input types (PaginationParams, ProductFilterInput, etc.) whose constructors may validate their arguments and throw.
Method of the class: ResolverHelpers{}
No Hooks.
Returns
Mixed. The return value of the factory.
Usage
$result = ResolverHelpers::create_input( $factory ): mixed;
- $factory(callable) (required)
- A callable that returns the constructed object.
ResolverHelpers::create_input() ResolverHelpers::create input code WC 10.9.1
public static function create_input( callable $factory ): mixed {
// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Not HTML; serialized as JSON.
try {
return $factory();
} catch ( \InvalidArgumentException $e ) {
throw new Error(
$e->getMessage(),
extensions: array( 'code' => 'INVALID_ARGUMENT' )
);
}
// phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped
}