app/Plugin/Api42/GraphQL/Schema.php line 45

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\Api42\GraphQL;
  13. use ArrayObject;
  14. use GraphQL\Type\Definition\ObjectType;
  15. class Schema extends \GraphQL\Type\Schema
  16. {
  17.     public function __construct(
  18.         Types $types,
  19.         ArrayObject $queries,
  20.         ArrayObject $mutations
  21.     ) {
  22.         parent::__construct([
  23.             'query' => new ObjectType([
  24.                 'name' => 'Query',
  25.                 'fields' => array_reduce($queries->getArrayCopy(), function ($accQuery $query) {
  26.                     $acc[$query->getName()] = $query->getQuery();
  27.                     return $acc;
  28.                 }, []),
  29.                 'typeLoader' => function ($name) use ($types) {
  30.                     return $types->get($name);
  31.                 },
  32.             ]),
  33.             'mutation' => new ObjectType([
  34.                 'name' => 'Mutation',
  35.                 'fields' => array_reduce($mutations->getArrayCopy(), function ($accMutation $mutation) {
  36.                     $acc[$mutation->getName()] = $mutation->getMutation();
  37.                     return $acc;
  38.                 }, []),
  39.                 'typeLoader' => function ($name) use ($types) {
  40.                     return $types->get($name);
  41.                 },
  42.             ]),
  43.         ]);
  44.     }
  45. }