You are here

public function ValidationController::report in GraphQL 8.4

Controller for the GraphiQL query builder IDE.

Parameters

\Drupal\graphql\Entity\ServerInterface $graphql_server: The GraphQL server entity.

Return value

array The render array.

1 string reference to 'ValidationController::report'
graphql.routing.yml in ./graphql.routing.yml
graphql.routing.yml

File

src/Controller/ValidationController.php, line 52

Class

ValidationController
Controller for the GraphiQL resolver validation.

Namespace

Drupal\graphql\Controller

Code

public function report(ServerInterface $graphql_server) {
  $build = [
    'validation' => [
      '#type' => 'table',
      '#caption' => $this
        ->t("Validation errors"),
      '#header' => [
        $this
          ->t('Type'),
        $this
          ->t('Field'),
        $this
          ->t('Message'),
      ],
      '#empty' => $this
        ->t("No validation errors."),
    ],
    'orphaned' => [
      '#type' => 'table',
      '#caption' => $this
        ->t("Resolvers without schema"),
      '#header' => [
        $this
          ->t('Type'),
        $this
          ->t('Fields'),
      ],
      '#empty' => $this
        ->t("No orphaned resolvers."),
    ],
    'missing' => [
      '#type' => 'table',
      '#caption' => $this
        ->t("Fields without resolvers"),
      '#header' => [
        $this
          ->t('Type'),
        $this
          ->t('Fields'),
      ],
      '#empty' => $this
        ->t("No missing resolvers."),
    ],
  ];
  foreach ($this->validator
    ->validateSchema($graphql_server) as $error) {
    $type = '';
    if (isset($error->nodes[1]) && property_exists($error->nodes[1], 'name')) {
      $type = $error->nodes[1]->name->value;
    }
    $field = '';
    if (isset($error->nodes[0]) && property_exists($error->nodes[0], 'name')) {
      $field = $error->nodes[0]->name->value;
    }
    $build['validation'][] = [
      'type' => [
        '#plain_text' => $type,
      ],
      'field' => [
        '#plain_text' => $field,
      ],
      'message' => [
        '#plain_text' => $error
          ->getMessage(),
      ],
    ];
  }

  // @todo Ability to configure ignores here.
  $metrics = [
    'orphaned' => $this->validator
      ->getOrphanedResolvers($graphql_server),
    'missing' => $this->validator
      ->getMissingResolvers($graphql_server),
  ];
  foreach ($metrics as $metric_type => $data) {
    foreach ($data as $type => $fields) {
      $build[$metric_type][$type] = [
        'type' => [
          '#plain_text' => $type,
        ],
        'fields' => [
          '#theme' => 'item_list',
          '#items' => $fields,
        ],
      ];
    }
  }
  return $build;
}