Skip to content

Commit

Permalink
Simply ignore non-executable definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Apr 13, 2022
1 parent 2c32186 commit 2c5ea6d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## v0.20.1

### Changed

- Simply ignore non-executable definitions

## v0.20.0

### Added
Expand Down
17 changes: 5 additions & 12 deletions src/Codegen/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use GraphQL\Error\Error;
use GraphQL\Error\SyntaxError;
use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\Parser;
use GraphQL\Type\Schema;
Expand Down Expand Up @@ -162,18 +161,12 @@ public static function validateDocuments(array $parsed): void
{
foreach ($parsed as $path => $documentNode) {
foreach ($documentNode->definitions as $definition) {
if ($definition instanceof OperationDefinitionNode) {
if (null === $definition->name) {
throw new Error('Found unnamed operation definition in ' . $path, $definition);
}
continue;
switch (true) {
case $definition instanceof OperationDefinitionNode:
if (null === $definition->name) {
throw new Error('Found unnamed operation definition in ' . $path, $definition);
}
}

if ($definition instanceof FragmentDefinitionNode) {
continue;
}

throw new Error('Found unsupported definition in ' . $path, $definition);
}
}
}
Expand Down
16 changes: 0 additions & 16 deletions tests/Unit/Codegen/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Spawnia\Sailor\Tests\Unit\Codegen;

use GraphQL\Error\Error;
use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\NameNode;
use GraphQL\Language\AST\OperationDefinitionNode;
Expand Down Expand Up @@ -103,21 +102,6 @@ public function testParseDocumentsThrowsErrorWithPath(): void
Generator::parseDocuments($documents);
}

public function testFailsOnNonExecutableDefinitions(): void
{
$somePath = 'path';
$documents = [
$somePath => Parser::parse(/* @lang GraphQL */ '
type Query {
foo: ID
}
'),
];

$this->expectException(Error::class);
Generator::validateDocuments($documents);
}

public function testEnsureOperationsAreNamedPasses(): void
{
self::expectNotToPerformAssertions();
Expand Down

0 comments on commit 2c5ea6d

Please sign in to comment.