Skip to content

Instantly share code, notes, and snippets.

@NandoKstroNet
Created April 12, 2020 22:26
Show Gist options
  • Save NandoKstroNet/222306b35bb895e8483a505dee0ee744 to your computer and use it in GitHub Desktop.
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)
<?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