Skip to content

Commit

Permalink
Merge pull request #48 from kiy0taka/dev/single-result-query
Browse files Browse the repository at this point in the history
ID指定でproduct/order/customerを取得するQueryを追加
  • Loading branch information
okazy committed Jul 27, 2020
2 parents 541924c + a92a8f8 commit 9d0e308
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 4 deletions.
32 changes: 32 additions & 0 deletions GraphQL/Query/CustomerQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL\Query;

use Eccube\Entity\Customer;

class CustomerQuery extends SingleResultQuery
{
/**
* CustomerQuery constructor.
*/
public function __construct()
{
parent::__construct(Customer::class);
}

public function getName()
{
return 'customer';
}
}
1 change: 0 additions & 1 deletion GraphQL/Query/CustomersQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Eccube\Entity\Customer;
use Eccube\Form\Type\Admin\SearchCustomerType;
use Eccube\Repository\CustomerRepository;
use Plugin\Api\GraphQL\SearchFormQuery;

class CustomersQuery extends SearchFormQuery
{
Expand Down
32 changes: 32 additions & 0 deletions GraphQL/Query/OrderQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL\Query;

use Eccube\Entity\Order;

class OrderQuery extends SingleResultQuery
{
/**
* OrderQuery constructor.
*/
public function __construct()
{
parent::__construct(Order::class);
}

public function getName()
{
return 'order';
}
}
1 change: 0 additions & 1 deletion GraphQL/Query/OrdersQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Eccube\Entity\Order;
use Eccube\Form\Type\Admin\SearchOrderType;
use Eccube\Repository\OrderRepository;
use Plugin\Api\GraphQL\SearchFormQuery;

class OrdersQuery extends SearchFormQuery
{
Expand Down
32 changes: 32 additions & 0 deletions GraphQL/Query/ProductQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL\Query;

use Eccube\Entity\Product;

class ProductQuery extends SingleResultQuery
{
/**
* ProductQuery constructor.
*/
public function __construct()
{
parent::__construct(Product::class);
}

public function getName()
{
return 'product';
}
}
1 change: 0 additions & 1 deletion GraphQL/Query/ProductsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Eccube\Entity\Product;
use Eccube\Form\Type\Admin\SearchProductType;
use Eccube\Repository\ProductRepository;
use Plugin\Api\GraphQL\SearchFormQuery;

class ProductsQuery extends SearchFormQuery
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL;
namespace Plugin\Api\GraphQL\Query;

use Eccube\Common\EccubeConfig;
use Eccube\Util\StringUtil;
use GraphQL\Type\Definition\Type;
use Knp\Component\Pager\Paginator;
use Plugin\Api\GraphQL\Error\FormInvalidException;
use Plugin\Api\GraphQL\Query;
use Plugin\Api\GraphQL\Type\ConnectionType;
use Plugin\Api\GraphQL\Types;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Form\FormInterface;
Expand Down
78 changes: 78 additions & 0 deletions GraphQL/Query/SingleResultQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL\Query;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use GraphQL\Type\Definition\Type;
use Plugin\Api\GraphQL\Query;
use Plugin\Api\GraphQL\Types;

abstract class SingleResultQuery implements Query
{
/**
* @var string
*/
private $entityClass;

/**
* @var Types
*/
private $types;

/**
* @var EntityManager
*/
private $entityManager;

/**
* SingleResultQuery constructor.
*/
public function __construct($entityClass)
{
$this->entityClass = $entityClass;
}

/**
* @param EntityManagerInterface $entityManager
* @required
*/
public function setEntityManager(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}

/**
* @param Types $types
* @required
*/
public function setTypes(Types $types): void
{
$this->types = $types;
}

public function getQuery()
{
return [
'type' => $this->types->get($this->entityClass),
'args' => [
'id' => Type::nonNull(Type::id()),
],
'resolve' => function ($root, $args) {
return $this->entityManager->getRepository($this->entityClass)->find($args['id']);
},
];

}
}

0 comments on commit 9d0e308

Please sign in to comment.