You are here

public function ProfileSchemaExtension::registerResolvers in Open Social 10.3.x

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

File

modules/social_features/social_profile/src/Plugin/GraphQL/SchemaExtension/ProfileSchemaExtension.php, line 24

Class

ProfileSchemaExtension
Adds user data to the Open Social GraphQL API.

Namespace

Drupal\social_profile\Plugin\GraphQL\SchemaExtension

Code

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

  // User type fields.
  $registry
    ->addFieldResolver('User', 'profile', $builder
    ->produce('default_profile_load')
    ->map('user', $builder
    ->fromParent()));

  // Profile type fields.
  $registry
    ->addFieldResolver('Profile', 'firstName', $builder
    ->fromPath('entity:profile', 'field_profile_first_name.0.value'));
  $registry
    ->addFieldResolver('Profile', 'lastName', $builder
    ->fromPath('entity:profile', 'field_profile_last_name.0.value'));
  $registry
    ->addFieldResolver('Profile', 'avatar', $builder
    ->produce('field')
    ->map('entity', $builder
    ->fromParent())
    ->map('field', $builder
    ->fromValue('field_profile_image')));

  // $value->getEntity()->get('field_profile_self_introduction')->first()->get('processed')->getString()
  $registry
    ->addFieldResolver('Profile', 'introduction', $builder
    ->produce('field')
    ->map('entity', $builder
    ->fromParent())
    ->map('field', $builder
    ->fromValue('field_profile_self_introduction')));
  $registry
    ->addFieldResolver('Profile', 'phone', $builder
    ->fromPath('entity:profile', 'field_profile_phone_number.0.value'));
  $registry
    ->addFieldResolver('Profile', 'function', $builder
    ->fromPath('entity:profile', 'field_profile_function.0.value'));
  $registry
    ->addFieldResolver('Profile', 'organization', $builder
    ->fromPath('entity:profile', 'field_profile_organization.0.value'));
}