TypeResolver.php in GraphQL 8.2
File
src/TypeResolver.php
View source
<?php
namespace Drupal\graphql;
class TypeResolver implements TypeResolverInterface {
protected $resolvers;
protected $sortedResolvers;
public function applies($type) {
return TRUE;
}
public function addTypeResolver(TypeResolverInterface $resolver, $priority = 0) {
$this->resolvers[$priority][] = $resolver;
$this->sortedResolvers = NULL;
}
protected function getFirstApplicableTypeResolver($type) {
foreach ($this
->getSortedResolvers() as $resolver) {
if ($resolver
->applies($type)) {
return $resolver;
}
}
return NULL;
}
protected function getSortedResolvers() {
if (!isset($this->sortedResolvers)) {
krsort($this->resolvers);
$this->sortedResolvers = [];
foreach ($this->resolvers as $resolvers) {
$this->sortedResolvers = array_merge($this->sortedResolvers, $resolvers);
}
}
return $this->sortedResolvers;
}
public function resolveRecursive($type) {
if ($resolver = $this
->getFirstApplicableTypeResolver($type)) {
return $resolver
->resolveRecursive($type);
}
return NULL;
}
}
Classes
Name |
Description |
TypeResolver |
Attempts to GraphQL type definitions from arbitrary data types. |