In preparation for introducing resolver registry caching later in the 5.x lifecycle, some methods in the \Drupal\graphql\Plugin\GraphQL\Schema\SdlSchemaPluginBase class have been changed. Implementers of this class (your base schema plugin) should adjust which methods they implement.
Methods change
getResolverRegistry should no longer be implemented. It is no longer an abstract function and is now implemented in SdlSchemaPluginBase. It currently implements static caching and in the future will implement caching the resolver registry as serialized object.
registerResolvers has been added as abstract method to SdlSchemaPluginBase and will be provided a resolver registry instance. You should implement this method and move any resolver registering from your base class into this method. This now follows the same pattern as is used for schema extensions.
createResolverRegistry has been added which now instantiates the \Drupal\graphql\GraphQL\ResolverRegistry by default. In case you want to use your own resolver registry in your schema you can overwrite this method to instantiate a different class implementing \Drupal\graphql\GraphQL\ResolverRegistryInterface.
getSchema no longer accepts a resolver registry instance and instead uses getResolverRegistry to retrieve the cached or instantiate a new resolver registry.
Example upgrade
Before
class ExampleSchema extends SdlSchemaPluginBase {
/**
* {@inheritdoc}
*/
public function getResolverRegistry(): ResolverRegistryInterface {
$builder = new ResolverBuilder();
$registry = new MyCustomResolverRegistry();
$this->addQueryFields($registry, $builder);
$this->addArticleFields($registry, $builder);
// Re-usable connection type fields.
$this->addConnectionFields('ArticleConnection', $registry, $builder);
return $registry;
}
}
After
class ExampleSchema extends SdlSchemaPluginBase {
/**
* {@inheritdoc}
*/
protected function registerResolvers(ResolverRegistryInterface $registry): void {
$builder = new ResolverBuilder();
$this->addQueryFields($registry, $builder);
$this->addArticleFields($registry, $builder);
// Re-usable connection type fields.
$this->addConnectionFields('ArticleConnection', $registry, $builder);
}
/**
* {@inheritdoc}
*/
protected function createResolverRegistry(): ResolverRegistryInterface {
return new MyCustomResolverRegistry();
}
}