/
ModelQuery.php
53 lines (47 loc) · 1.59 KB
/
ModelQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace SilverStripe\GraphQL\Schema\Field;
use SilverStripe\GraphQL\Schema\Exception\SchemaBuilderException;
use SilverStripe\GraphQL\Schema\Interfaces\FieldPlugin;
use SilverStripe\GraphQL\Schema\Interfaces\ModelFieldPlugin;
use SilverStripe\GraphQL\Schema\Interfaces\ModelOperation;
use SilverStripe\GraphQL\Schema\Interfaces\ModelQueryPlugin;
use SilverStripe\GraphQL\Schema\Interfaces\QueryPlugin;
use SilverStripe\GraphQL\Schema\Interfaces\SchemaModelInterface;
use SilverStripe\GraphQL\Schema\Schema;
/**
* Defines a query generated by a model
*/
class ModelQuery extends ModelField implements ModelOperation
{
/**
* ModelQuery constructor.
* @param SchemaModelInterface $model
* @param string $queryName
* @param array $config
* @throws SchemaBuilderException
*/
public function __construct(SchemaModelInterface $model, string $queryName, array $config = [])
{
$this->setModel($model);
parent::__construct($queryName, $config, $model);
}
/**
* @param string $pluginName
* @param $plugin
* @throws SchemaBuilderException
*/
public function validatePlugin(string $pluginName, $plugin): void
{
Schema::invariant(
$plugin && (
$plugin instanceof ModelQueryPlugin ||
$plugin instanceof QueryPlugin ||
$plugin instanceof ModelFieldPlugin ||
$plugin instanceof FieldPlugin
),
'Plugin %s not found or does not apply to model query "%s"',
$pluginName,
$this->getName()
);
}
}