-
Notifications
You must be signed in to change notification settings - Fork 106
Closed
Labels
documentationRelated to errors, omissions and improvements to docsRelated to errors, omissions and improvements to docs
Description
Consider the following situation - no idea how to handle this without this annotation. Any ideas or alternate approaches?
The goal here is to not have to create separate input type classes for Dimensions where there is already a good domain model class that can be used.
class ProductController
{
public function createProduct(CreateProduct $input) { // stuff }
public function updateProduct(UpdateProduct $input) { // stuff }
}class CreateProduct
{
/**
* Factory to make a CreateProductInput type
*
* @GraphQLite\Factory()
* @GraphQLite\UseInputType(for="$dimensions", inputType="CreateDimensionsInput")
*/
public static function make(
Money $price,
float $weight,
Dimensions $dimensions,
...
): CreateProduct
{
$product = new self();
$product->setPrice($price);
$product->setWeight($weight);
...
return $product;
}
}class UpdateProduct
{
/**
* Factory to make a UpdateProductInput type
*
* @GraphQLite\Factory()
* @GraphQLite\UseInputType(for="$dimensions", inputType="UpdateDimensionsInput")
*/
public static function make(
Money $price,
float $weight,
Dimensions $dimensions,
...
): UpdateProduct
{
$product = new self();
$product->setPrice($price);
$product->setWeight($weight);
...
return $product;
}
}class CreateDimensions
{
/**
* Factory to make a CreateDimensionsInput type
*
* @GraphQLite\Factory(name="CreateDimensionsInput", default=false)
*/
public static function make(
float $height,
float $length,
float $width,
...
): Dimensions
{
$dimensions = new Dimensions();
$dimensions->setHeight($height);
$dimensions->setLength($length);
$dimensions->setWidth($width);
...
return $dimensions;
}
}class UpdateDimensions
{
/**
* Factory to make a UpdateDimensionsInput type
*
* @GraphQLite\Factory(name="UpdateDimensionsInput", default=false)
*/
public static function make(
ID, $id,
float $height,
float $length,
float $width,
...
): Dimensions
{
$dimensions = $this->get('dimensions_repository')->findOrDie($id);
$dimensions->setHeight($height);
$dimensions->setLength($length);
$dimensions->setWidth($width);
...
return $dimensions;
}
}Metadata
Metadata
Assignees
Labels
documentationRelated to errors, omissions and improvements to docsRelated to errors, omissions and improvements to docs