View source
<?php
namespace Drupal\social_graphql\Plugin\GraphQL\Schema;
use Drupal\graphql\GraphQL\ResolverBuilder;
use Drupal\graphql\GraphQL\ResolverRegistryInterface;
use Drupal\graphql\Plugin\GraphQL\Schema\SdlSchemaPluginBase;
use Drupal\social_graphql\GraphQL\ResolverRegistry;
class OpenSocialBaseSchema extends SdlSchemaPluginBase {
public function getResolverRegistry() {
return new ResolverRegistry();
}
public function getSchema(ResolverRegistryInterface $registry) {
$this
->getBaseSchema($registry);
return parent::getSchema($registry);
}
protected function getBaseSchema(ResolverRegistryInterface $registry) {
$builder = new ResolverBuilder();
$registry
->addFieldResolver('TextFormat', 'name', $builder
->fromParent());
$registry
->addFieldResolver('FormattedText', 'format', $builder
->fromPath('text', 'format'));
$registry
->addFieldResolver('FormattedText', 'raw', $builder
->fromPath('text', 'value'));
$registry
->addFieldResolver('FormattedText', 'processed', $builder
->fromPath('text', 'processed'));
$registry
->addFieldResolver('DateTime', 'timestamp', $builder
->fromParent());
$registry
->addFieldResolver('Media', 'id', $builder
->produce('media_bridge')
->map('value', $builder
->fromParent())
->map('field', $builder
->fromValue('id')));
$registry
->addFieldResolver('Media', 'url', $builder
->produce('media_bridge')
->map('value', $builder
->fromParent())
->map('field', $builder
->fromValue('url')));
$registry
->addFieldResolver('Image', 'title', $builder
->produce('media_bridge')
->map('value', $builder
->fromParent())
->map('field', $builder
->fromValue('title')));
$registry
->addFieldResolver('Image', 'alt', $builder
->produce('media_bridge')
->map('value', $builder
->fromParent())
->map('field', $builder
->fromValue('alt')));
$registry
->addFieldResolver('Connection', 'edges', $builder
->produce('connection_edges')
->map('connection', $builder
->fromParent()));
$registry
->addFieldResolver('Connection', 'nodes', $builder
->produce('connection_nodes')
->map('connection', $builder
->fromParent()));
$registry
->addFieldResolver('Connection', 'pageInfo', $builder
->produce('connection_page_info')
->map('connection', $builder
->fromParent()));
$registry
->addFieldResolver('Edge', 'cursor', $builder
->produce('edge_cursor')
->map('edge', $builder
->fromParent()));
$registry
->addFieldResolver('Edge', 'node', $builder
->produce('edge_node')
->map('edge', $builder
->fromParent()));
}
}