|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql\GraphQL\QueryProvider; |
|
4
|
|
|
|
|
5
|
|
|
use GraphQL\Server\OperationParams; |
|
6
|
|
|
|
|
7
|
|
|
class QueryProvider implements QueryProviderInterface { |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Unsorted list of query providers nested and keyed by priority. |
|
11
|
|
|
* |
|
12
|
|
|
* @var \Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface[] |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $providers = []; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Sorted list of query providers. |
|
18
|
|
|
* |
|
19
|
|
|
* @var \Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface[] |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $sortedProviders; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
public function getQuery($id, OperationParams $operation) { |
|
27
|
|
|
foreach ($this->getSortedProviders() as $provider) { |
|
28
|
|
|
if ($query = $provider->getQuery($id, $operation)) { |
|
29
|
|
|
return $query; |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
return NULL; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Adds a query provider. |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface $provider |
|
40
|
|
|
* The query provider to add. |
|
41
|
|
|
* @param int $priority |
|
42
|
|
|
* Priority of the query provider. |
|
43
|
|
|
*/ |
|
44
|
|
|
public function addQueryProvider(QueryProviderInterface $provider, $priority = 0) { |
|
45
|
|
|
$this->providers[$priority][] = $provider; |
|
46
|
|
|
$this->sortedProviders = NULL; |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns the sorted array of query providers. |
|
51
|
|
|
* |
|
52
|
|
|
* @return \Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface[] |
|
53
|
|
|
* An array of query provider objects. |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function getSortedProviders() { |
|
56
|
|
|
if (!isset($this->sortedProviders)) { |
|
57
|
|
|
krsort($this->providers); |
|
58
|
|
|
|
|
59
|
|
|
$this->sortedProviders = []; |
|
60
|
|
|
foreach ($this->providers as $providers) { |
|
61
|
|
|
$this->sortedProviders = array_merge($this->sortedProviders, $providers); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $this->sortedProviders; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..