From 3908e824098e861a5b64465837e68eb962d1c600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Dobe=C5=A1?= Date: Wed, 4 Jun 2025 09:17:12 +0200 Subject: [PATCH 1/2] List invalid schema errors as tips --- src/GraphQL/CorrespondanceRule.php | 17 ++++++++++++++--- src/GraphQL/SchemaClassGenerator.php | 11 ++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/GraphQL/CorrespondanceRule.php b/src/GraphQL/CorrespondanceRule.php index c2d6f66..ee75d9b 100644 --- a/src/GraphQL/CorrespondanceRule.php +++ b/src/GraphQL/CorrespondanceRule.php @@ -45,12 +45,23 @@ public function processNode(PhpParser\Node $node, PHPStan\Analyser\Scope $scope) } if ($this->reflectionProvider->hasClass($invalidClassName)) { - $result[] = PHPStan\Rules\RuleErrorBuilder::message("GraphQL schema isn't valid.") + $ruleError = PHPStan\Rules\RuleErrorBuilder::message("GraphQL schema isn't valid.") ->identifier('graphql.schemaInvalid') ->file($schemaName) ->line(0) - ->nonIgnorable() - ->build(); + ->nonIgnorable(); + + $errors = $this->reflectionProvider + ->getClass($invalidClassName) + ->getNativeProperty('errors') + ->getNativeReflection() + ->getDefaultValue(); + + foreach ($errors as $error) { + $ruleError = $ruleError->addTip($error['message']); + } + + $result[] = $ruleError->build(); continue; } diff --git a/src/GraphQL/SchemaClassGenerator.php b/src/GraphQL/SchemaClassGenerator.php index bc05afd..31c9c76 100644 --- a/src/GraphQL/SchemaClassGenerator.php +++ b/src/GraphQL/SchemaClassGenerator.php @@ -57,7 +57,16 @@ private function generateInvalidSchemaClass( $file = new Nette\PhpGenerator\PhpFile(); $file->setStrictTypes(); - $file->addClass($invalidClassName); + $class = $file->addClass($invalidClassName); + + $class->addProperty('errors') + ->setPublic() + ->setValue( + array_map( + static fn ($error) => $error->toResponse(), + $e->errors, + ), + ); Nette\Utils\FileSystem::write( "{$this->generatedDir}/{$invalidClassName}.php", From e1de535e02696212001c23afe7fde2796e412715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Dobe=C5=A1?= Date: Wed, 4 Jun 2025 09:27:53 +0200 Subject: [PATCH 2/2] Remove dot from "invalid schema" error --- src/GraphQL/CorrespondanceRule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GraphQL/CorrespondanceRule.php b/src/GraphQL/CorrespondanceRule.php index ee75d9b..e3e8e9f 100644 --- a/src/GraphQL/CorrespondanceRule.php +++ b/src/GraphQL/CorrespondanceRule.php @@ -45,7 +45,7 @@ public function processNode(PhpParser\Node $node, PHPStan\Analyser\Scope $scope) } if ($this->reflectionProvider->hasClass($invalidClassName)) { - $ruleError = PHPStan\Rules\RuleErrorBuilder::message("GraphQL schema isn't valid.") + $ruleError = PHPStan\Rules\RuleErrorBuilder::message("GraphQL schema isn't valid") ->identifier('graphql.schemaInvalid') ->file($schemaName) ->line(0)