SchemaProvider.php in GraphQL 8.2        
                          
                  
                        
  
  
  
  
File
  src/SchemaProvider.php
  
    View source  
  <?php
namespace Drupal\graphql;
class SchemaProvider implements SchemaProviderInterface {
  
  protected $providers;
  
  protected $sortedProviders;
  
  public function getQuerySchema() {
    return array_reduce($this
      ->getSortedProviders(), function ($carry, SchemaProviderInterface $provider) {
      return array_merge($carry, $provider
        ->getQuerySchema() ?: []);
    }, []);
  }
  
  public function getMutationSchema() {
    return array_reduce($this
      ->getSortedProviders(), function ($carry, SchemaProviderInterface $provider) {
      return array_merge($carry, $provider
        ->getMutationSchema() ?: []);
    }, []);
  }
  
  public function addSchemaProvider(SchemaProviderInterface $provider, $priority = 0) {
    $this->providers[$priority][] = $provider;
    $this->sortedProviders = NULL;
  }
  
  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;
  }
}