Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Don't validate the schema again when validating the query against it
Browse files Browse the repository at this point in the history
Fixes #324
  • Loading branch information
Sam Stenvall committed Nov 8, 2018
1 parent 7f81372 commit 81e2772
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 43 deletions.
17 changes: 0 additions & 17 deletions src/Schema/Validation/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,6 @@ public function validate(Schema $schema, ?array $rules = null): array
return $context->getErrors();
}

/**
* @param Schema $schema
* @throws SchemaValidationException
*/
public function assertValid(Schema $schema): void
{
$errors = $this->validate($schema);

if (!empty($errors)) {
$message = \implode("\n", \array_map(function (SchemaValidationException $error) {
return $error->getMessage();
}, $errors));

throw new SchemaValidationException($message);
}
}

/**
* @inheritdoc
*/
Expand Down
5 changes: 0 additions & 5 deletions src/Schema/Validation/SchemaValidatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ interface SchemaValidatorInterface
*/
public function validate(Schema $schema, ?array $rules = null): array;

/**
* @param Schema $schema
*/
public function assertValid(Schema $schema): void;

/**
* @param Schema $schema
* @return ValidationContextInterface
Expand Down
5 changes: 1 addition & 4 deletions src/Validation/ValidationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Digia\GraphQL\Validation;

use Digia\GraphQL\Schema\Validation\SchemaValidatorInterface;
use League\Container\ServiceProvider\AbstractServiceProvider;

class ValidationProvider extends AbstractServiceProvider
Expand All @@ -19,8 +18,6 @@ class ValidationProvider extends AbstractServiceProvider
*/
public function register()
{
$this->container
->share(ValidatorInterface::class, Validator::class)
->addArgument(SchemaValidatorInterface::class);
$this->container->share(ValidatorInterface::class, Validator::class);
}
}
17 changes: 0 additions & 17 deletions src/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,12 @@
use Digia\GraphQL\Language\Visitor\TypeInfoVisitor;
use Digia\GraphQL\Language\Visitor\VisitorInfo;
use Digia\GraphQL\Schema\Schema;
use Digia\GraphQL\Schema\Validation\SchemaValidatorInterface;
use Digia\GraphQL\Util\TypeInfo;
use Digia\GraphQL\Validation\Rule\RuleInterface;
use Digia\GraphQL\Validation\Rule\SupportedRules;

class Validator implements ValidatorInterface
{
/**
* @var SchemaValidatorInterface
*/
protected $schemaValidator;

/**
* Validator constructor.
* @param SchemaValidatorInterface $schemaValidator
*/
public function __construct(SchemaValidatorInterface $schemaValidator)
{
$this->schemaValidator = $schemaValidator;
}

/**
* @inheritdoc
*/
Expand All @@ -37,8 +22,6 @@ public function validate(
?array $rules = null,
?TypeInfo $typeInfo = null
): array {
$this->schemaValidator->assertValid($schema);

$typeInfo = $typeInfo ?? new TypeInfo($schema);
$rules = $rules ?? SupportedRules::build();

Expand Down

0 comments on commit 81e2772

Please sign in to comment.