Skip to content

Commit e7cfae1

Browse files
authored
Merge branch 'master' into dependabot/composer/monolog/monolog-tw-2.8.0
2 parents 36fcbae + 8f0e829 commit e7cfae1

File tree

26 files changed

+669
-76
lines changed

26 files changed

+669
-76
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
symfony-version: '5.4.*'
3232
dependencies: 'lowest'
3333
remove-dependencies: '--dev symfony/validator doctrine/orm doctrine/annotations'
34-
- php-version: '8.0'
34+
- php-version: '8.1'
3535
symfony-version: '5.4.*'
3636
dependencies: 'lowest'
3737
coverage: "pcov"
@@ -86,7 +86,7 @@ jobs:
8686
uses: "shivammathur/setup-php@v2"
8787
with:
8888
tools: flex
89-
php-version: "8.0"
89+
php-version: "8.1"
9090

9191
- name: "Install dependencies"
9292
uses: ramsey/composer-install@v2
@@ -101,7 +101,6 @@ jobs:
101101
fail-fast: false
102102
matrix:
103103
php-version:
104-
- '8.0'
105104
- '8.1'
106105
steps:
107106
- name: "Checkout"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ OverblogGraphQLBundle
99
[![Total Downloads](https://poser.pugx.org/overblog/graphql-bundle/downloads)](https://packagist.org/packages/overblog/graphql-bundle)
1010

1111
This Symfony bundle provides integration of [GraphQL](https://facebook.github.io/graphql/) using [webonyx/graphql-php](https://github.com/webonyx/graphql-php)
12-
and [GraphQL Relay](https://facebook.github.io/relay/docs/en/graphql-server-specification.html).
12+
and [GraphQL Relay](https://relay.dev/docs/guides/graphql-server-specification/).
1313
It also supports:
1414
* batching with [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer)
1515
* batching with [Apollo GraphQL](https://www.apollographql.com/docs/react/api/link/apollo-link-batch-http/)

docs/definitions/type-system/enum.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,57 @@ class Episode
5757
public $value;
5858
}
5959
```
60+
61+
## Working with native PHP 8.1 enums
62+
63+
Given a PHP enum as follow:
64+
65+
```php
66+
namespace App;
67+
68+
enum Color
69+
{
70+
case RED;
71+
case GREEN;
72+
case BLUE;
73+
}
74+
```
75+
76+
You can declare it with annotations or attributes as follow:
77+
78+
```php
79+
#[GQL\Enum]
80+
enum Color
81+
{
82+
#[GQL\Description("The color red")]
83+
case RED;
84+
case GREEN;
85+
case BLUE;
86+
}
87+
```
88+
89+
or with YAML:
90+
91+
```yaml
92+
Color:
93+
type: enum
94+
config:
95+
enumClass: App\Color
96+
```
97+
98+
The possible values will be automatically extracted from the enum but if you need to add description and/or deprecated, you can proceed this way
99+
100+
```yaml
101+
Color:
102+
type: enum
103+
config:
104+
enumClass: App\Color
105+
values:
106+
GREEN:
107+
description: "The color green"
108+
```
109+
When using PHP enum, the serialization will extract the `name` of the enum case, and the deserialization will return the enum case by its `name`.
110+
Even if the used enum is a Backed enum, the serialization and deserialization will always use the `name` and not the value.
111+
112+
113+

phpstan-baseline.neon

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -481,87 +481,87 @@ parameters:
481481
path: tests/Functional/Validator/DummyEntity.php
482482

483483
-
484-
message: "#^Cannot access offset mixed on iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\>\\.$#"
484+
message: "#^Cannot access offset mixed on iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\<mixed\\>\\>\\.$#"
485485
count: 2
486486
path: tests/Relay/Connection/AbstractConnectionBuilderTest.php
487487

488488
-
489-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\> given\\.$#"
489+
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\<mixed\\>\\> given\\.$#"
490490
count: 1
491491
path: tests/Relay/Connection/AbstractConnectionBuilderTest.php
492492

493493
-
494-
message: "#^Cannot access offset 0 on iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\>\\.$#"
494+
message: "#^Cannot access offset 0 on iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\<mixed\\>\\>\\.$#"
495495
count: 4
496496
path: tests/Relay/Connection/ConnectionBuilderTest.php
497497

498498
-
499-
message: "#^Cannot access offset 1 on iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\>\\.$#"
499+
message: "#^Cannot access offset 1 on iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\<mixed\\>\\>\\.$#"
500500
count: 4
501501
path: tests/Relay/Connection/ConnectionBuilderTest.php
502502

503503
-
504-
message: "#^Cannot access offset 2 on iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\>\\.$#"
504+
message: "#^Cannot access offset 2 on iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\<mixed\\>\\>\\.$#"
505505
count: 1
506506
path: tests/Relay/Connection/ConnectionBuilderTest.php
507507

508508
-
509-
message: "#^Cannot access offset 3 on iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\>\\.$#"
509+
message: "#^Cannot access offset 3 on iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\<mixed\\>\\>\\.$#"
510510
count: 1
511511
path: tests/Relay/Connection/ConnectionBuilderTest.php
512512

513513
-
514-
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\:\\:\\$cursor\\.$#"
514+
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\<mixed\\>\\:\\:\\$extra\\.$#"
515515
count: 1
516516
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
517517

518518
-
519-
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\:\\:\\$node\\.$#"
519+
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\PageInfoInterface\\:\\:\\$endCursor\\.$#"
520520
count: 1
521521
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
522522

523523
-
524-
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\:\\:\\$extra\\.$#"
524+
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\PageInfoInterface\\:\\:\\$hasNextPage\\.$#"
525525
count: 1
526526
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
527527

528528
-
529-
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\PageInfoInterface\\:\\:\\$endCursor\\.$#"
529+
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\PageInfoInterface\\:\\:\\$hasPreviousPage\\.$#"
530530
count: 1
531531
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
532532

533533
-
534-
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\PageInfoInterface\\:\\:\\$hasNextPage\\.$#"
534+
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\PageInfoInterface\\:\\:\\$startCursor\\.$#"
535535
count: 1
536536
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
537537

538538
-
539-
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\PageInfoInterface\\:\\:\\$hasPreviousPage\\.$#"
539+
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\<mixed\\>\\:\\:\\$edges\\.$#"
540540
count: 1
541541
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
542542

543543
-
544-
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\PageInfoInterface\\:\\:\\$startCursor\\.$#"
544+
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\<mixed\\>\\:\\:\\$pageInfo\\.$#"
545545
count: 1
546546
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
547547

548548
-
549-
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\:\\:\\$edges\\.$#"
550-
count: 2
549+
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\<string\\>\\:\\:\\$edges\\.$#"
550+
count: 1
551551
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
552552

553553
-
554-
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\:\\:\\$pageInfo\\.$#"
555-
count: 2
554+
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\<string\\>\\:\\:\\$pageInfo\\.$#"
555+
count: 1
556556
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
557557

558558
-
559-
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Edge\\:\\:\\$cursor\\.$#"
559+
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Edge\\<null\\>\\:\\:\\$cursor\\.$#"
560560
count: 1
561561
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
562562

563563
-
564-
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Edge\\:\\:\\$node\\.$#"
564+
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Edge\\<null\\>\\:\\:\\$node\\.$#"
565565
count: 1
566566
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
567567

@@ -585,3 +585,18 @@ parameters:
585585
count: 1
586586
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
587587

588+
-
589+
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\) with 'node' and null will always evaluate to false\\.$#"
590+
count: 1
591+
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
592+
593+
-
594+
message: "#^Cannot access offset 0 on iterable\\<Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\EdgeInterface\\<string\\>\\>\\.$#"
595+
count: 4
596+
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
597+
598+
-
599+
message: "#^Property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Edge\\<null\\>\\:\\:\\$node \\(null\\) does not accept string\\.$#"
600+
count: 1
601+
path: tests/Relay/Connection/Output/DeprecatedPropertyPublicAccessTraitTest.php
602+

src/Config/EnumTypeDefinition.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ public function getDefinition(): ArrayNodeDefinition
2121
$node
2222
->children()
2323
->append($this->nameSection())
24+
->scalarNode('enumClass')
25+
->validate()
26+
->ifTrue(fn () => PHP_VERSION_ID < 80100)
27+
->thenInvalid('The enumClass option requires PHP 8.1 or higher.')
28+
->end()
29+
->validate()
30+
->ifTrue(fn ($v) => !class_exists($v))
31+
->thenInvalid('The specified enum Class "%s" does not exist.')
32+
->end()
33+
->end()
2434
->arrayNode('values')
2535
->useAttributeAsKey('name')
2636
->beforeNormalization()
@@ -49,8 +59,6 @@ public function getDefinition(): ArrayNodeDefinition
4959
->append($this->deprecationReasonSection())
5060
->end()
5161
->end()
52-
->isRequired()
53-
->requiresAtLeastOneElement()
5462
->end()
5563
->append($this->descriptionSection())
5664
->end();

src/Config/Parser/MetadataParser/MetadataParser.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
use function substr;
4343
use function trim;
4444

45+
use const PHP_VERSION_ID;
46+
4547
abstract class MetadataParser implements PreParserInterface
4648
{
4749
public const ANNOTATION_NAMESPACE = 'Overblog\GraphQLBundle\Annotation\\';
@@ -434,15 +436,15 @@ private static function enumMetadataToGQLConfiguration(ReflectionClass $reflecti
434436
{
435437
$metadatas = static::getMetadatas($reflectionClass);
436438
$enumValues = self::getMetadataMatching($metadatas, Metadata\EnumValue::class);
437-
439+
$isPhpEnum = PHP_VERSION_ID >= 80100 && $reflectionClass->isEnum();
438440
$values = [];
439441

440442
foreach ($reflectionClass->getConstants() as $name => $value) {
441443
$reflectionConstant = new ReflectionClassConstant($reflectionClass->getName(), $name);
442444
$valueConfig = self::getDescriptionConfiguration(static::getMetadatas($reflectionConstant), true);
443445

444446
$enumValueAnnotation = current(array_filter($enumValues, fn ($enumValueAnnotation) => $enumValueAnnotation->name === $name));
445-
$valueConfig['value'] = $value;
447+
$valueConfig['value'] = $isPhpEnum ? $value->name : $value;
446448

447449
if (false !== $enumValueAnnotation) {
448450
if (isset($enumValueAnnotation->description)) {
@@ -459,6 +461,9 @@ private static function enumMetadataToGQLConfiguration(ReflectionClass $reflecti
459461

460462
$enumConfiguration = ['values' => $values];
461463
$enumConfiguration = self::getDescriptionConfiguration(static::getMetadatas($reflectionClass)) + $enumConfiguration;
464+
if ($isPhpEnum) {
465+
$enumConfiguration['enumClass'] = $reflectionClass->getName();
466+
}
462467

463468
return ['type' => 'enum', 'config' => $enumConfiguration];
464469
}

0 commit comments

Comments
 (0)