Skip to content

Commit

Permalink
Merge pull request #10 from pyrou/patch-5
Browse files Browse the repository at this point in the history
Support Lighthouse 6. New Major release. Not backwards compatible with Lighthouse 5.
  • Loading branch information
peterkeijsers authored Aug 4, 2023
2 parents 9b462f7 + 8445f57 commit 04d2e67
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 82 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
laravel-version:
- "^6"
- "^7"
- "^8"
- "^9"
- "^10"
composer-flags:
Expand All @@ -32,22 +28,9 @@ jobs:
# Laravel 10.x doesn't support PHP 8.0.
- php-version: 8.0
laravel-version: ^10
# Laravel 10.x doesn't support PHP 7.4.
- php-version: 7.4
laravel-version: ^10
# Laravel 9.x doesn't support PHP 7.4.
- php-version: 7.4
laravel-version: ^9
# Laravel 6.x doesn't support PHP 8.1.
- php-version: 8.1
laravel-version: ^6
# Older dev-tools don't properly support PHP 8.1.
- php-version: 8.1
composer-flags: --prefer-lowest
include:
# Count PHP 8.1 as experimental (CI failures allowed).
- php-version: 8.1
experimental: true

steps:
- name: "Checkout"
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"phpVersion": "7.4",
"phpVersion": "8.0",
"singleQuote": true
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ This library allows integrating your Lighthouse GraphQL project with Apollo Stud
sending tracing statistics and allowing you to send your schema to Apollo for
breaking changes notifications.

## Requirements
## Lighthouse requirements

- PHP 7.4 or newer
- Tested with Laravel 8 and Lighthouse 5.26
This library is tested with Lighthouse 6.

For Lighthouse 4.x, use version `1.x` of this library.
For Lighthouse 5.x, use version `2.x` of this library.

## Installation

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
],
"minimum-stability": "stable",
"require": {
"php": ">=7.4",
"php": ">=8.0",
"ext-curl": "*",
"ext-json": "*",
"ext-zlib": "*",
"czproject/git-php": "^4.0",
"google/protobuf": "^v3.13.0.1",
"illuminate/redis": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
"nuwave/lighthouse": "^5.3"
"illuminate/redis": "^9.0 || ^10.0",
"illuminate/support": "^9.0 || ^10.0",
"nuwave/lighthouse": "^6.0"
},
"require-dev": {
"phpunit/phpunit": "^9.4",
"vimeo/psalm": "^4.0"
"vimeo/psalm": "^4.30"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/Actions/SendTracingToApollo.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function getReportWithTraces(array $tracesPerQuery): Report
*/
public function normalizeQuery(
string $query,
?string $operationName
?string $operationName,
): string {
$trimmed = trim(preg_replace('/[\r\n\s]+/', ' ', $query));
if ($operationName !== null) {
Expand Down Expand Up @@ -247,7 +247,7 @@ private function serializeProtobufWithProtoc(Report $report): string
private function writeProtobufValue(
$process,
$value,
bool $isRootObject = false
bool $isRootObject = false,
): void {
if (is_bool($value)) {
fwrite($process, $value ? 'true' : 'false');
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/RegisterSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function handle(SchemaBuilder $schemaBuilder): void
* @throws JsonException
*/
protected function sendSchemaToApollo(
UploadSchemaVariables $variables
UploadSchemaVariables $variables,
): array {
$request = curl_init(
$this->config->get('lighthouse-apollo.schema_reporting_endpoint'),
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/SubmitTracing.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public function handle(SchemaBuilder $schemaBuilder): int

private function handleFromRedis(
RedisConnector $connector,
SchemaBuilder $schemaBuilder
SchemaBuilder $schemaBuilder,
): int {
$total = $connector->chunk(function (array $tracings) use (
$connector,
$schemaBuilder
$schemaBuilder,
) {
$this->output->writeln(
'Sending ' . count($tracings) . ' tracing(s) to Apollo Studio',
Expand Down
10 changes: 3 additions & 7 deletions src/Connectors/RedisConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use GraphQL\Language\AST\DirectiveDefinitionNode;
use GraphQL\Language\AST\EnumTypeDefinitionNode;
use GraphQL\Language\AST\EnumTypeExtensionNode;
use GraphQL\Language\AST\ExecutableDefinitionNode;
use GraphQL\Language\AST\FieldDefinitionNode;
use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
use GraphQL\Language\AST\InputObjectTypeExtensionNode;
Expand All @@ -23,9 +22,7 @@
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\AST\ScalarTypeDefinitionNode;
use GraphQL\Language\AST\ScalarTypeExtensionNode;
use GraphQL\Language\AST\SchemaDefinitionNode;
use GraphQL\Language\AST\SchemaTypeExtensionNode;
use GraphQL\Language\AST\TypeDefinitionNode;
use GraphQL\Language\AST\SchemaExtensionNode;
use GraphQL\Language\AST\UnionTypeDefinitionNode;
use GraphQL\Language\AST\UnionTypeExtensionNode;
use GraphQL\Language\AST\VariableDefinitionNode;
Expand Down Expand Up @@ -181,7 +178,7 @@ protected function fetchTracingsFromRedis(int $count): array

return array_map(
static fn(
string $serializedTracingResult
string $serializedTracingResult,
): TracingResult => unserialize($serializedTracingResult, [
'allowed_classes' => [
// Only allow decoding tracing results.
Expand Down Expand Up @@ -233,8 +230,7 @@ protected function fetchTracingsFromRedis(int $count): array
ObjectTypeExtensionNode::class,
ScalarTypeDefinitionNode::class,
ScalarTypeExtensionNode::class,
SchemaDefinitionNode::class,
SchemaTypeExtensionNode::class,
SchemaExtensionNode::class,
UnionTypeDefinitionNode::class,
UnionTypeExtensionNode::class,
],
Expand Down
2 changes: 1 addition & 1 deletion src/Graph/GitContextInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
?string $commit,
?string $committer,
?string $message,
?string $remoteUrl
?string $remoteUrl,
) {
$this->branch = $branch;
$this->commit = $commit;
Expand Down
2 changes: 1 addition & 1 deletion src/Graph/UploadSchemaVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(
string $id,
string $schemaDocument,
string $tag,
?GitContextInput $gitContext
?GitContextInput $gitContext,
) {
$this->id = $id;
$this->tag = $tag;
Expand Down
9 changes: 6 additions & 3 deletions src/Listeners/ManipulateResultListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(
Container $container,
QueryRequestStack $requestStack,
Request $request,
SchemaBuilder $schemaBuilder
SchemaBuilder $schemaBuilder,
) {
$this->clientInformationExtractor = $clientInformationExtractor;
$this->config = $config;
Expand Down Expand Up @@ -184,9 +184,12 @@ private function extractHttpInformation(): array
}

private function removeTracingFromExtensionsIfNeeded(
ManipulateResult $event
ManipulateResult $event,
): void {
if ($this->config->get('lighthouse-apollo.mute_tracing_extensions')) {
if (
$this->config->get('lighthouse-apollo.mute_tracing_extensions') &&
$event->result->extensions
) {
unset($event->result->extensions['tracing']);
}
}
Expand Down
42 changes: 29 additions & 13 deletions src/Tracing/ReferencedFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\Visitor;
use GraphQL\Type\Definition\InterfaceType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\UnionType;
use GraphQL\Type\Schema;
use GraphQL\Utils\TypeInfo;
use LogicException;
Expand All @@ -22,11 +24,12 @@ class ReferencedFields
{
/**
* @return array<string, ReferencedFieldsForType>
* @throws \Exception
*/
public static function calculateReferencedFieldsByType(
DocumentNode $document,
Schema $schema,
?string $resolvedOperationName
?string $resolvedOperationName,
): array {
// If the document contains multiple operations, we only care about fields
// referenced in the operation we're using and in fragments that are
Expand Down Expand Up @@ -58,13 +61,15 @@ public static function calculateReferencedFieldsByType(
Visitor::visit(
$filteredDocument,
Visitor::visitWithTypeInfo($typeInfo, [
NodeKind::FIELD => function (FieldNode $field) use (
NodeKind::FIELD => function (Node $field) use (
$filteredDocument,
&$interfaces,
&$referencedFieldSetByType,
$typeInfo
$typeInfo,
): void {
/** @var FieldNode $field */
$fieldName = $field->name->value;
/** @var ObjectType|InterfaceType|UnionType|null $parentType */
$parentType = $typeInfo->getParentType();
if ($parentType === null) {
throw new LogicException(
Expand Down Expand Up @@ -103,6 +108,7 @@ public static function calculateReferencedFieldsByType(

/**
* @return array<string, DocumentNode>
* @throws \Exception
*/
private static function separateOperations(DocumentNode $document): array
{
Expand All @@ -119,23 +125,33 @@ private static function separateOperations(DocumentNode $document): array

// Populate metadata and build a dependency graph.
Visitor::visit($document, [
NodeKind::OPERATION_DEFINITION => function (
OperationDefinitionNode $node
) use (&$fromName, &$idx, &$operations, &$positions): void {
NodeKind::OPERATION_DEFINITION => function (Node $node) use (
&$fromName,
&$idx,
&$operations,
&$positions,
): void {
/** @var OperationDefinitionNode $node */
$fromName = $node->name->value ?? '';
$operations[] = $node;
$positions[$fromName] = $idx++;
},
NodeKind::FRAGMENT_DEFINITION => function (
FragmentDefinitionNode $node
) use (&$fromName, &$idx, &$fragments, &$positions): void {
NodeKind::FRAGMENT_DEFINITION => function (Node $node) use (
&$fromName,
&$idx,
&$fragments,
&$positions,
): void {
/** @var FragmentDefinitionNode $node */
$fromName = $node->name->value;
$fragments[$fromName] = $node;
$positions[$fromName] = $idx++;
},
NodeKind::FRAGMENT_SPREAD => function (
FragmentSpreadNode $node
) use (&$fromName, &$depGraph): void {
NodeKind::FRAGMENT_SPREAD => function (Node $node) use (
&$fromName,
&$depGraph,
): void {
/** @var FragmentSpreadNode $node */
$toName = $node->name->value;
if (!isset($depGraph[$fromName])) {
$depGraph[$fromName] = [];
Expand Down Expand Up @@ -195,7 +211,7 @@ private static function separateOperations(DocumentNode $document): array
private static function collectTransitiveDependencies(
array &$collected,
array $depGraph,
string $fromName
string $fromName,
): void {
$immediateDeps = $depGraph[$fromName] ?? null;

Expand Down
4 changes: 2 additions & 2 deletions src/Tracing/TraceTreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function applyHttp(array $http): void
{
if (isset($http['request_headers'])) {
$http['request_headers'] = array_map(static function (
array $values
array $values,
) {
return new Trace\HTTP\Values(['value' => $values]);
},
Expand Down Expand Up @@ -251,7 +251,7 @@ public static function errorToProtobufError(array $error): Error
* earlier by Lighthouse.
*/
private static function dateTimeStringToTimestampField(
string $dateTime
string $dateTime,
): Timestamp {
$timestamp = new Timestamp();
$timestamp->fromDateTime(new DateTime($dateTime));
Expand Down
2 changes: 1 addition & 1 deletion src/TracingResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(
array $client,
array $http,
array $tracing,
array $errors
array $errors,
) {
$this->document = $document;
$this->queryText = $queryText;
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/QueryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct()
$val,
$args,
$context,
ResolveInfo $info
ResolveInfo $info,
) {
return $this->{$info->fieldName}($val, $args, $context, $info);
},
Expand Down
Loading

0 comments on commit 04d2e67

Please sign in to comment.