class SchemaProvider in GraphQL 8
Same name and namespace in other branches
- 8.2 src/SchemaProvider.php \Drupal\graphql\SchemaProvider
Generates a GraphQL Schema.
Hierarchy
- class \Drupal\graphql\SchemaProvider implements SchemaProviderInterface
Expanded class hierarchy of SchemaProvider
1 string reference to 'SchemaProvider'
1 service uses SchemaProvider
File
- src/
SchemaProvider.php, line 8
Namespace
Drupal\graphqlView source
class SchemaProvider implements SchemaProviderInterface {
/**
* Unsorted list of schema providers nested and keyed by priority.
*
* @var array
*/
protected $providers;
/**
* Sorted list of schema providers.
*
* @var array
*/
protected $sortedProviders;
/**
* {@inheritdoc}
*/
public function getQuerySchema() {
return array_reduce($this
->getSortedProviders(), function ($carry, SchemaProviderInterface $provider) {
return array_merge($carry, $provider
->getQuerySchema() ?: []);
}, []);
}
/**
* {@inheritdoc}
*/
public function getMutationSchema() {
return array_reduce($this
->getSortedProviders(), function ($carry, SchemaProviderInterface $provider) {
return array_merge($carry, $provider
->getMutationSchema() ?: []);
}, []);
}
/**
* Adds a active theme negotiation service.
*
* @param \Drupal\graphql\SchemaProviderInterface $provider
* The schema provider to add.
* @param int $priority
* Priority of the schema provider.
*/
public function addSchemaProvider(SchemaProviderInterface $provider, $priority = 0) {
$this->providers[$priority][] = $provider;
$this->sortedProviders = NULL;
}
/**
* Returns the sorted array of schema providers.
*
* @return \Drupal\graphql\SchemaProviderInterface[]
* An array of schema provider objects.
*/
protected function getSortedProviders() {
if (!isset($this->sortedProviders)) {
krsort($this->providers);
$this->sortedProviders = [];
foreach ($this->providers as $providers) {
$this->sortedProviders = array_merge($this->sortedProviders, $providers);
}
}
return $this->sortedProviders;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SchemaProvider:: |
protected | property | Unsorted list of schema providers nested and keyed by priority. | |
SchemaProvider:: |
protected | property | Sorted list of schema providers. | |
SchemaProvider:: |
public | function | Adds a active theme negotiation service. | |
SchemaProvider:: |
public | function |
Overrides SchemaProviderInterface:: |
|
SchemaProvider:: |
public | function |
Overrides SchemaProviderInterface:: |
|
SchemaProvider:: |
protected | function | Returns the sorted array of schema providers. |