From 2c5ea6d0abbf53a5580f30d9e82c4c57db264f54 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 13 Apr 2022 17:27:57 +0200 Subject: [PATCH] Simply ignore non-executable definitions --- CHANGELOG.md | 6 ++++++ src/Codegen/Generator.php | 17 +++++------------ tests/Unit/Codegen/GeneratorTest.php | 16 ---------------- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 142bd652..a438d640 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Codegen/Generator.php b/src/Codegen/Generator.php index 0b0c4a56..be86b6fd 100644 --- a/src/Codegen/Generator.php +++ b/src/Codegen/Generator.php @@ -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; @@ -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); } } } diff --git a/tests/Unit/Codegen/GeneratorTest.php b/tests/Unit/Codegen/GeneratorTest.php index 846a733e..348b78e3 100644 --- a/tests/Unit/Codegen/GeneratorTest.php +++ b/tests/Unit/Codegen/GeneratorTest.php @@ -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; @@ -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();