Skip to content

Commit

Permalink
LighthouseIntegration: Fix finding the operation definition node on t…
Browse files Browse the repository at this point in the history
…he query (#883)

* Fix finding the operation definition node on the query

* Fix baseline
  • Loading branch information
stayallive committed Apr 17, 2024
1 parent 7604023 commit 3fd21f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 3fd21f9

Please sign in to comment.