Skip to content

Commit

Permalink
Improve stubs for PHP 8.2 and above (#2441)
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia authored Aug 29, 2023
1 parent 21ae33c commit 00d80dd
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ You can find and compare releases at the [GitHub release page](https://github.co

## Unreleased

## v6.17.0

### Added

- Improve stubs for PHP 8.2 and above https://github.com/nuwave/lighthouse/pull/2441

## v6.16.2

### Fixed
Expand Down
12 changes: 8 additions & 4 deletions src/Console/FieldGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ abstract class FieldGeneratorCommand extends LighthouseGeneratorCommand

protected function getStub(): string
{
$stub = $this->option('full')
? 'field_full'
: 'field_simple';
if (version_compare(PHP_VERSION, '8.2.0', '>=')) {
return $this->option('full')
? __DIR__ . '/stubs/field_full.php82.stub'
: __DIR__ . '/stubs/field_simple.php82.stub';
}

return __DIR__ . "/stubs/{$stub}.stub";
return $this->option('full')
? __DIR__ . '/stubs/field_full.stub'
: __DIR__ . '/stubs/field_simple.stub';
}

/** @return array<int, array<int, mixed>> */
Expand Down
2 changes: 1 addition & 1 deletion src/Console/stubs/directive.stub
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace DummyNamespace;

Expand Down
23 changes: 23 additions & 0 deletions src/Console/stubs/field_full.php82.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);

namespace DummyNamespace;

use Nuwave\Lighthouse\Execution\ResolveInfo;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;

final readonly class DummyClass
{
/**
* Return a value for the field.
*
* @param null $root Always null, since this field has no parent.
* @param array{} $args The field arguments passed by the client.
* @param \Nuwave\Lighthouse\Support\Contracts\GraphQLContext $context Shared between all fields.
* @param \GraphQL\Type\Definition\ResolveInfo $resolveInfo Metadata for advanced query resolution.
* @return mixed The result of resolving the field, matching what was promised in the schema
*/
public function __invoke(null $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): mixed
{
// TODO implement the resolver
}
}
6 changes: 3 additions & 3 deletions src/Console/stubs/field_full.stub
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace DummyNamespace;

Expand All @@ -14,9 +14,9 @@ final class DummyClass
* @param array{} $args The field arguments passed by the client.
* @param \Nuwave\Lighthouse\Support\Contracts\GraphQLContext $context Shared between all fields.
* @param \GraphQL\Type\Definition\ResolveInfo $resolveInfo Metadata for advanced query resolution.
* @return mixed
* @return mixed The result of resolving the field, matching what was promised in the schema
*/
public function __invoke(mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo)
public function __invoke(mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): mixed
{
// TODO implement the resolver
}
Expand Down
12 changes: 12 additions & 0 deletions src/Console/stubs/field_simple.php82.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace DummyNamespace;

final readonly class DummyClass
{
/** @param array{} $args */
public function __invoke(null $_, array $args)
{
// TODO implement the resolver
}
}
2 changes: 1 addition & 1 deletion src/Console/stubs/field_simple.stub
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace DummyNamespace;

Expand Down
14 changes: 4 additions & 10 deletions src/Console/stubs/scalar.stub
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
<?php
<?php declare(strict_types=1);

namespace DummyNamespace;

use GraphQL\Language\AST\Node;
use GraphQL\Type\Definition\ScalarType;

/**
* Read more about scalars here https://webonyx.github.io/graphql-php/type-definitions/scalars
*/
/** Read more about scalars here: https://webonyx.github.io/graphql-php/type-definitions/scalars. */
final class DummyClass extends ScalarType
{
/**
* Serializes an internal value to include in a response.
*/
/** Serializes an internal value to include in a response. */
public function serialize(mixed $value): mixed
{
// TODO validate if $value might be incorrect
}

/**
* Parses an externally provided value (query variable) to use as an input
*/
/** Parses an externally provided value (query variable) to use as an input. */
public function parseValue(mixed $value): mixed
{
// TODO implement validation and transformation of $value
Expand Down
10 changes: 3 additions & 7 deletions src/Console/stubs/subscription.stub
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace DummyNamespace;

Expand All @@ -8,17 +8,13 @@ use Nuwave\Lighthouse\Schema\Types\GraphQLSubscription;

final class DummyClass extends GraphQLSubscription
{
/**
* Check if subscriber is allowed to listen to the subscription.
*/
/** Check if subscriber is allowed to listen to the subscription. */
public function authorize(Subscriber $subscriber, Request $request): bool
{
// TODO implement authorize
}

/**
* Filter which subscribers should receive the subscription.
*/
/** Filter which subscribers should receive the subscription. */
public function filter(Subscriber $subscriber, mixed $root): bool
{
// TODO implement filter
Expand Down
2 changes: 1 addition & 1 deletion src/Console/stubs/tests/pest.stub
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

use Tests\TestCase;

Expand Down
2 changes: 1 addition & 1 deletion src/Console/stubs/tests/phpunit.stub
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace DummyNamespace;

Expand Down
4 changes: 2 additions & 2 deletions src/Console/stubs/typeResolver.stub
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace DummyNamespace;

Expand All @@ -10,7 +10,7 @@ use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
final class DummyClass
{
public function __construct(
private TypeRegistry $typeRegistry;
private TypeRegistry $typeRegistry,
) {}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Console/stubs/validator.stub
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace DummyNamespace;

Expand Down

0 comments on commit 00d80dd

Please sign in to comment.