Skip to content

Commit 3fd21f9

Browse files
authored
LighthouseIntegration: Fix finding the operation definition node on the query (#883)
* Fix finding the operation definition node on the query * Fix baseline
1 parent 7604023 commit 3fd21f9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

phpstan-baseline.neon

+10
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ parameters:
135135
count: 1
136136
path: src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php
137137

138+
-
139+
message: "#^Method Sentry\\\\Laravel\\\\Tracing\\\\Integrations\\\\LighthouseIntegration\\:\\:extractOperationDefinitionNode\\(\\) has invalid return type GraphQL\\\\Language\\\\AST\\\\OperationDefinitionNode\\.$#"
140+
count: 1
141+
path: src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php
142+
138143
-
139144
message: "#^Parameter \\$endExecution of method Sentry\\\\Laravel\\\\Tracing\\\\Integrations\\\\LighthouseIntegration\\:\\:handleEndExecution\\(\\) has invalid type Nuwave\\\\Lighthouse\\\\Events\\\\EndExecution\\.$#"
140145
count: 1
@@ -150,6 +155,11 @@ parameters:
150155
count: 1
151156
path: src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php
152157

158+
-
159+
message: "#^Parameter \\$query of method Sentry\\\\Laravel\\\\Tracing\\\\Integrations\\\\LighthouseIntegration\\:\\:extractOperationDefinitionNode\\(\\) has invalid type GraphQL\\\\Language\\\\AST\\\\DocumentNode\\.$#"
160+
count: 1
161+
path: src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php
162+
153163
-
154164
message: "#^Parameter \\$startExecution of method Sentry\\\\Laravel\\\\Tracing\\\\Integrations\\\\LighthouseIntegration\\:\\:handleStartExecution\\(\\) has invalid type Nuwave\\\\Lighthouse\\\\Events\\\\StartExecution\\.$#"
155165
count: 1

src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ public function handleStartExecution(StartExecution $startExecution): void
125125
return;
126126
}
127127

128-
/** @var \GraphQL\Language\AST\OperationDefinitionNode|null $operationDefinition */
129-
$operationDefinition = $startExecution->query->definitions[0] ?? null;
128+
$operationDefinition = $this->extractOperationDefinitionNode($startExecution->query);
130129

131-
if (!$operationDefinition instanceof OperationDefinitionNode) {
130+
if ($operationDefinition === null) {
132131
return;
133132
}
134133

@@ -239,6 +238,17 @@ private function extractOperationNames(OperationDefinitionNode $operation): arra
239238
return $selectionSet;
240239
}
241240

241+
private function extractOperationDefinitionNode(DocumentNode $query): ?OperationDefinitionNode
242+
{
243+
foreach ($query->definitions as $definition) {
244+
if ($definition instanceof OperationDefinitionNode) {
245+
return $definition;
246+
}
247+
}
248+
249+
return null;
250+
}
251+
242252
private function isApplicable(): bool
243253
{
244254
if (!class_exists(StartRequest::class) || !class_exists(StartExecution::class)) {

0 commit comments

Comments
 (0)