Created
April 12, 2020 22:26
-
-
Save NandoKstroNet/222306b35bb895e8483a505dee0ee744 to your computer and use it in GitHub Desktop.
Série sobre GraphQL com Symfony 4 do canal da Code Experts no Youtube (http://youtube.com/CodeExpertsLearning)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\GraphQL\Mutation; | |
use Doctrine\ORM\EntityManager; | |
use OverBlog\GraphQLBundle\Definition\Argument; | |
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface; | |
use Overblog\GraphQLBundle\Definition\Resolver\MutationInterface; | |
use App\Entity\Product; | |
class ProductMutation implements MutationInterface, AliasedInterface | |
{ | |
private $em; | |
public function __construct(EntityManager $em) | |
{ | |
$this->em = $em; | |
} | |
public function createProduct(Argument $args) | |
{ | |
$input = $args['input']; | |
$product = new Product(); | |
$product->setName($input['name']); | |
$product->setPrice($input['price']); | |
$product->setSlug($input['slug']); | |
$product->setDescription($input['description']); | |
$this->em->persist($product); | |
$this->em->flush(); | |
return $product; | |
} | |
public static function getAliases() | |
{ | |
return [ | |
'createProduct' => 'create_product' | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment