diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7879f79b..7860608a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -135,6 +135,11 @@ parameters: count: 1 path: src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php + - + message: "#^Method Sentry\\\\Laravel\\\\Tracing\\\\Integrations\\\\LighthouseIntegration\\:\\:extractOperationDefinitionNode\\(\\) has invalid return type GraphQL\\\\Language\\\\AST\\\\OperationDefinitionNode\\.$#" + count: 1 + path: src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php + - message: "#^Parameter \\$endExecution of method Sentry\\\\Laravel\\\\Tracing\\\\Integrations\\\\LighthouseIntegration\\:\\:handleEndExecution\\(\\) has invalid type Nuwave\\\\Lighthouse\\\\Events\\\\EndExecution\\.$#" count: 1 @@ -150,6 +155,11 @@ parameters: count: 1 path: src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php + - + message: "#^Parameter \\$query of method Sentry\\\\Laravel\\\\Tracing\\\\Integrations\\\\LighthouseIntegration\\:\\:extractOperationDefinitionNode\\(\\) has invalid type GraphQL\\\\Language\\\\AST\\\\DocumentNode\\.$#" + count: 1 + path: src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php + - message: "#^Parameter \\$startExecution of method Sentry\\\\Laravel\\\\Tracing\\\\Integrations\\\\LighthouseIntegration\\:\\:handleStartExecution\\(\\) has invalid type Nuwave\\\\Lighthouse\\\\Events\\\\StartExecution\\.$#" count: 1 diff --git a/src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php b/src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php index 46c011d7..789b6dcd 100644 --- a/src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php +++ b/src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php @@ -125,10 +125,9 @@ public function handleStartExecution(StartExecution $startExecution): void return; } - /** @var \GraphQL\Language\AST\OperationDefinitionNode|null $operationDefinition */ - $operationDefinition = $startExecution->query->definitions[0] ?? null; + $operationDefinition = $this->extractOperationDefinitionNode($startExecution->query); - if (!$operationDefinition instanceof OperationDefinitionNode) { + if ($operationDefinition === null) { return; } @@ -239,6 +238,17 @@ private function extractOperationNames(OperationDefinitionNode $operation): arra return $selectionSet; } + private function extractOperationDefinitionNode(DocumentNode $query): ?OperationDefinitionNode + { + foreach ($query->definitions as $definition) { + if ($definition instanceof OperationDefinitionNode) { + return $definition; + } + } + + return null; + } + private function isApplicable(): bool { if (!class_exists(StartRequest::class) || !class_exists(StartExecution::class)) {