You are here

public function ContextDeriver::getDerivativeDefinitions in GraphQL 8.3

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

modules/graphql_core/src/Plugin/Deriver/Fields/ContextDeriver.php, line 41

Class

ContextDeriver

Namespace

Drupal\graphql_core\Plugin\Deriver\Fields

Code

public function getDerivativeDefinitions($basePluginDefinition) {
  if (empty($this->derivatives)) {
    foreach ($this->contextRepository
      ->getAvailableContexts() as $id => $context) {
      $this->derivatives[$id] = [
        'name' => StringHelper::propCase($id, 'context'),
        'context_id' => $id,
        'type' => $context
          ->getContextDefinition()
          ->getDataType(),
      ];

      // Add cache contexts, if available
      if ($context instanceof CacheableDependencyInterface) {
        $this->derivatives[$id]['response_cache_contexts'] = $context
          ->getCacheContexts();
      }

      // Add default base
      $this->derivatives[$id] += $basePluginDefinition;
    }
  }
  return parent::getDerivativeDefinitions($basePluginDefinition);
}