diff --git a/src/Actions/SendTracingToApollo.php b/src/Actions/SendTracingToApollo.php index 91f36b0..9ff622c 100644 --- a/src/Actions/SendTracingToApollo.php +++ b/src/Actions/SendTracingToApollo.php @@ -192,6 +192,7 @@ private function transformTracing(TracingResult $tracingResult): Trace return empty($error['path']) || empty($tracingResult->tracing['execution']['resolvers']); }) ); + /** @var Trace\Node|null $rootNode */ $rootNode = $result->getRoot(); if ($rootNode === null) { $result->setRoot($rootNode = new Trace\Node([ diff --git a/src/Commands/RegisterSchema.php b/src/Commands/RegisterSchema.php index 35dc51c..fa98e50 100644 --- a/src/Commands/RegisterSchema.php +++ b/src/Commands/RegisterSchema.php @@ -98,7 +98,7 @@ public function handle(): void $response = ($this->sendSchemaToApollo($variables)); if (!empty($response['errors'])) { - throw new RegisterSchemaFailedException(implode(', ', array_map(function ($error) { + throw new RegisterSchemaFailedException(implode(', ', array_map(function (array $error): string { return $error['message']; }, $response['errors']))); } @@ -110,7 +110,7 @@ public function handle(): void } /** - * @param array $variables + * @param UploadSchemaVariables $variables * @return array * @throws RegisterSchemaRequestFailedException * @throws JsonException @@ -135,7 +135,7 @@ protected function sendSchemaToApollo(UploadSchemaVariables $variables): array $response = curl_exec($request); $errorCode = curl_errno($request); - if ($errorCode) { + if ($errorCode || !is_string($response)) { throw new RegisterSchemaRequestFailedException($errorCode, curl_error($request)); } diff --git a/src/Graph/ArrayableTrait.php b/src/Graph/ArrayableTrait.php index 1f0796c..5b54710 100644 --- a/src/Graph/ArrayableTrait.php +++ b/src/Graph/ArrayableTrait.php @@ -6,6 +6,12 @@ trait ArrayableTrait { + /** + * Convert a field to something for an array. + * + * @param mixed $field + * @return mixed + */ private function mapField($field) { if ($field instanceof Arrayable) { @@ -24,6 +30,11 @@ private function mapField($field) return $field; } + /** + * Get the instance as an array. + * + * @return array + */ public function toArray(): array { return array_map([$this, 'mapField'], get_object_vars($this)); diff --git a/src/Listeners/ManipulateResultListener.php b/src/Listeners/ManipulateResultListener.php index 8c2d008..45851ae 100644 --- a/src/Listeners/ManipulateResultListener.php +++ b/src/Listeners/ManipulateResultListener.php @@ -75,7 +75,7 @@ public function handle(ManipulateResult $event): void if ( !isset($event->result->extensions['tracing']) && - !isset($event->result->errors) + !count($event->result->errors) ) { return; } @@ -87,7 +87,7 @@ public function handle(ManipulateResult $event): void $event->result->extensions['tracing'] ?? [], array_map(function (Error $error) { return FormattedError::createFromException($error, true); - }, $event->result->errors ?? []), + }, $event->result->errors), ); $this->removeTracingFromExtensionsIfNeeded($event); @@ -100,19 +100,14 @@ public function handle(ManipulateResult $event): void ->send(); } catch (Exception $e) { // We should probably not cause pain for the end users. Just include this in the extensions instead. - if (!isset($event->result->extensions['errors'])) { - $event->result->extensions['errors'] = []; - } - - $event->result->extensions['errors'][] = [ - 'message' => $e->getMessage(), - 'extensions' => array_merge([ - 'type' => get_class($e), - 'code' => $e->getCode(), - ], $this->config->get('app.debug') ? [ - 'trace' => $e->getTraceAsString(), - ] : []), - ]; + $event->result->errors[] = new Error( + 'Failed to send tracing to Apollo', + null, + null, + null, + null, + $e + ); } break; case 'redis': diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 3a482c8..6508700 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -38,7 +38,7 @@ public function register(): void private function bootForConsole(): void { $this->publishes([ - __DIR__ . '/../config/lighthouse-apollo.php' => config_path('lighthouse-apollo.php') + __DIR__ . '/../config/lighthouse-apollo.php' => $this->app->configPath('lighthouse-apollo.php') ], 'lighthouse-apollo'); $this->commands([ diff --git a/src/TracingResult.php b/src/TracingResult.php index 006f9ce..499feec 100644 --- a/src/TracingResult.php +++ b/src/TracingResult.php @@ -14,16 +14,17 @@ class TracingResult /** * @var array{ - * duration: int - * endTime: string - * startTime: string - * version: int + * duration: int, + * endTime: string, + * startTime: string, + * version: int, * execution: array{ * resolvers: array{ - * duration: int - * parentType: string - * path: string - * returnType: string + * duration: int, + * fieldName: string, + * parentType: string, + * path: (int|string)[], + * returnType: string, * startOffset: int * }[] * }