You are here

public function UserSchemaExtension::registerResolvers in Open Social 10.2.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_user/src/Plugin/GraphQL/SchemaExtension/UserSchemaExtension.php \Drupal\social_user\Plugin\GraphQL\SchemaExtension\UserSchemaExtension::registerResolvers()
  2. 10.0.x modules/social_features/social_user/src/Plugin/GraphQL/SchemaExtension/UserSchemaExtension.php \Drupal\social_user\Plugin\GraphQL\SchemaExtension\UserSchemaExtension::registerResolvers()
  3. 10.1.x modules/social_features/social_user/src/Plugin/GraphQL/SchemaExtension/UserSchemaExtension.php \Drupal\social_user\Plugin\GraphQL\SchemaExtension\UserSchemaExtension::registerResolvers()

File

modules/social_features/social_user/src/Plugin/GraphQL/SchemaExtension/UserSchemaExtension.php, line 25

Class

UserSchemaExtension
Adds user data to the Open Social GraphQL API.

Namespace

Drupal\social_user\Plugin\GraphQL\SchemaExtension

Code

public function registerResolvers(ResolverRegistryInterface $registry) {
  $builder = new ResolverBuilder();

  // Type resolvers.
  $registry
    ->addTypeResolver('Actor', new UserActorTypeResolver($registry
    ->getTypeResolver('Actor')));

  // Root Query fields.
  $registry
    ->addFieldResolver('Query', 'viewer', $builder
    ->produce('viewer'));
  $registry
    ->addFieldResolver('Query', 'users', $builder
    ->produce('query_user')
    ->map('after', $builder
    ->fromArgument('after'))
    ->map('before', $builder
    ->fromArgument('before'))
    ->map('first', $builder
    ->fromArgument('first'))
    ->map('last', $builder
    ->fromArgument('last'))
    ->map('reverse', $builder
    ->fromArgument('reverse'))
    ->map('sortKey', $builder
    ->fromArgument('sortKey')));
  $registry
    ->addFieldResolver('Query', 'user', $builder
    ->produce('entity_load_by_uuid')
    ->map('type', $builder
    ->fromValue('user'))
    ->map('uuid', $builder
    ->fromArgument('id')));

  // User type fields.
  $registry
    ->addFieldResolver('User', 'id', $builder
    ->produce('entity_uuid')
    ->map('entity', $builder
    ->fromParent()));
  $registry
    ->addFieldResolver('User', 'displayName', $builder
    ->produce('entity_label')
    ->map('entity', $builder
    ->fromParent()));
  $registry
    ->addFieldResolver('User', 'mail', $builder
    ->fromPath('entity:user', 'mail.value'));
  $registry
    ->addFieldResolver('User', 'created', $builder
    ->fromPath('entity:user', 'created.value'));
  $registry
    ->addFieldResolver('User', 'updated', $builder
    ->fromPath('entity:user', 'changed.value'));
  $registry
    ->addFieldResolver('User', 'status', $builder
    ->produce('user_status')
    ->map('user', $builder
    ->fromParent()));
  $registry
    ->addFieldResolver('User', 'roles', $builder
    ->produce('user_roles')
    ->map('user', $builder
    ->fromParent()));
}