You are here

EntityCrudOutputErrors.php in GraphQL 8.3

File

modules/graphql_core/src/Plugin/GraphQL/Fields/Mutations/EntityCrudOutputErrors.php
View source
<?php

namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Mutations;

use Drupal\graphql\GraphQL\Execution\ResolveContext;
use Drupal\graphql_core\GraphQL\EntityCrudOutputWrapper;
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
use GraphQL\Type\Definition\ResolveInfo;

/**
 * Retrieve a list of error messages.
 *
 * @GraphQLField(
 *   id = "entity_crud_output_errors",
 *   secure = true,
 *   name = "errors",
 *   type = "[String]",
 *   parents = {"EntityCrudOutput"}
 * )
 */
class EntityCrudOutputErrors extends FieldPluginBase {

  /**
   * {@inheritdoc}
   */
  public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
    if ($value instanceof EntityCrudOutputWrapper) {
      if ($errors = $value
        ->getErrors()) {
        foreach ($errors as $error) {
          (yield $error);
        }
      }
    }
  }

}

Classes

Namesort descending Description
EntityCrudOutputErrors Retrieve a list of error messages.