-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from kiy0taka/dev/single-result-query
ID指定でproduct/order/customerを取得するQueryを追加
- Loading branch information
Showing
8 changed files
with
177 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
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'; | ||
} | ||
} |
This file contains 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
This file contains 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
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'; | ||
} | ||
} |
This file contains 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
This file contains 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
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'; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
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']); | ||
}, | ||
]; | ||
|
||
} | ||
} |