You are here

public function ResolverRegistry::addMutationResolver in Open Social 10.1.x

Add a field resolver for a mutation field.

Calling this function is equivalent to writing out the following code manually:

``` $field_name = camelCaseTOsnake_case($fieldName); $this->addFieldResolver('Mutation', $fieldName, $builder->compose( $builder->produce($field_name . "_input") ->map('input', $builder->fromArgument('input')), $builder->produce($field_name) ->map('input', $builder->fromParent()) ) ); ```

Parameters

\Drupal\graphql\GraphQL\ResolverBuilder $builder: The resolver builder.

string $field_name: A camelCased field name. This will be converted into snake_case for the IDs of the used data producers.

File

modules/custom/social_graphql/src/GraphQL/ResolverRegistry.php, line 52

Class

ResolverRegistry
The Open Social resolver registry.

Namespace

Drupal\social_graphql\GraphQL

Code

public function addMutationResolver(ResolverBuilder $builder, string $field_name) : void {
  $words = array_map('strtolower', preg_split('/(?=[A-Z])/', $field_name, -1, PREG_SPLIT_NO_EMPTY));
  $data_producer = implode("_", $words);
  $this
    ->addFieldResolver('Mutation', $field_name, $builder
    ->compose($builder
    ->produce($data_producer . "_input")
    ->map('input', $builder
    ->fromArgument('input')), $builder
    ->produce($data_producer)
    ->map('input', $builder
    ->fromParent())));
}