Skip to content

Commit f37f644

Browse files
committed
Change annotation attributes names
1 parent 9ed385f commit f37f644

File tree

7 files changed

+35
-22
lines changed

7 files changed

+35
-22
lines changed

docs/annotations/annotations-reference.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -382,17 +382,17 @@ class SecretArea {
382382

383383
This annotation applies on methods for classes tagged with the `@Provider` annotation. It indicates that the method on this class will resolve a Mutation field.
384384
The corresponding GraphQL field is added to the GraphQL type(s) following the logic:
385-
- The type(s) specified in the `targetType` attribute of the `@Mutation` annotation if it's defined.
385+
- The type(s) specified in the `targetTypes` attribute of the `@Mutation` annotation if it's defined.
386386
or
387-
- The type(s) specified in the `targetTypeMutation` attribute of the `@Provider` annotation if it's defined.
387+
- The type(s) specified in the `targetMutationTypes` attribute of the `@Provider` annotation if it's defined.
388388
or
389389
- The root Query type of the default schema (defined in configuration at key `overblog_graphql.definitions.schema.mutation` or `overblog_graphql.definitions.schema.default.mutation`).
390390

391391
The class exposing the mutation(s) must be declared as a [service](https://symfony.com/doc/current/service_container.html).
392392

393393
Optional attributes:
394394

395-
- **targetType** : The GraphQL type(s) to attach the field to. It must be a mutation. (by default, it'll be the root Mutation type of the default schema. see [Default Schema](../definitions/schema.md#default-schema)). You can specify one or multiple target types.
395+
- **targetTypes** : The GraphQL type(s) to attach the field to. It must be a mutation. (by default, it'll be the root Mutation type of the default schema. see [Default Schema](../definitions/schema.md#default-schema)). You can specify one or multiple target types.
396396

397397
Example:
398398

@@ -440,17 +440,17 @@ Optional attributes:
440440

441441
This annotation applies on methods for classes tagged with the `@Provider` annotation. It indicates that on this class a method will resolve a Query field.
442442
The corresponding GraphQL field is added to the GraphQL type(s) following the logic:
443-
- The type(s) specified in the `targetType` attribute of the `@Query` annotation if it's defined.
443+
- The type(s) specified in the `targetTypes` attribute of the `@Query` annotation if it's defined.
444444
or
445-
- The type(s) specified in the `targetTypeQuery` attribute of the `@Provider` annotation if it's defined.
445+
- The type(s) specified in the `targetQueryTypes` attribute of the `@Provider` annotation if it's defined.
446446
or
447447
- The root Query type of the default schema (defined in configuration at key `overblog_graphql.definitions.schema.query` or `overblog_graphql.definitions.schema.default.query`).
448448

449449
The class exposing the query(ies) must be declared as a [service](https://symfony.com/doc/current/service_container.html).
450450

451451
Optional attributes:
452452

453-
- **targetType** : The GraphQL type(s) to attach the field to (by default, it'll be the root Query type of the default schema. see [Default Schema](../definitions/schema.md#default-schema)). You can specify one or multiple target types.
453+
- **targetTypes** : The GraphQL type(s) to attach the field to (by default, it'll be the root Query type of the default schema. see [Default Schema](../definitions/schema.md#default-schema)). You can specify one or multiple target types.
454454

455455
Example:
456456

src/Annotation/Mutation.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
*/
1313
final class Mutation extends Field
1414
{
15+
/**
16+
* @deprecated
17+
* @var array<string>
18+
*/
19+
public array $targetType;
20+
1521
/**
1622
* The target types to attach this mutation to (useful when multiple schemas are allowed).
1723
*
1824
* @var array<string>
1925
*/
20-
public array $targetType;
26+
public array $targetTypes;
2127
}

src/Annotation/Provider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ final class Provider implements Annotation
2424
*
2525
* @var array<string>
2626
*/
27-
public array $targetTypeQuery;
27+
public array $targetQueryTypes;
2828

2929
/**
3030
* The default target types to attach the provider mutations to.
3131
*
3232
* @var array<string>
3333
*/
34-
public array $targetTypeMutation;
34+
public array $targetMutationTypes;
3535
}

src/Annotation/Query.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
*/
1313
final class Query extends Field
1414
{
15+
/**
16+
* @deprecated
17+
* @var array<string>
18+
*/
19+
public array $targetType;
20+
1521
/**
1622
* The target types to attach this query to.
1723
*
1824
* @var array<string>
1925
*/
20-
public array $targetType;
26+
public array $targetTypes;
2127
}

src/Config/Parser/AnnotationParser.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -710,13 +710,14 @@ private static function getGraphQLFieldsFromProviders(GraphClass $graphClass, st
710710
continue;
711711
}
712712

713-
$annotationTargets = $annotation->targetType ?? null;
713+
// TODO: Remove old property check in 1.1
714+
$annotationTargets = $annotation->targetTypes ?? $annotation->targetType ?? null;
714715

715716
if (null === $annotationTargets) {
716-
if ($annotation instanceof GQL\Mutation && isset($providerAnnotation->targetTypeMutation)) {
717-
$annotationTargets = $providerAnnotation->targetTypeMutation;
718-
} elseif ($annotation instanceof GQL\Query && isset($providerAnnotation->targetTypeQuery)) {
719-
$annotationTargets = $providerAnnotation->targetTypeQuery;
717+
if ($annotation instanceof GQL\Mutation && isset($providerAnnotation->targetMutationTypes)) {
718+
$annotationTargets = $providerAnnotation->targetMutationTypes;
719+
} elseif ($annotation instanceof GQL\Query && isset($providerAnnotation->targetQueryTypes)) {
720+
$annotationTargets = $providerAnnotation->targetQueryTypes;
720721
}
721722
}
722723

tests/Config/Parser/fixtures/annotations/Repository/PlanetRepository.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public function getAllowedPlanetsForDroids(): array
4545
}
4646

4747
/**
48-
* @GQL\Query(type="Planet", targetType="RootQuery2")
48+
* @GQL\Query(type="Planet", targetTypes="RootQuery2")
4949
*/
5050
public function getPlanetSchema2(): ?Planet
5151
{
5252
return null;
5353
}
5454

5555
/**
56-
* @GQL\Mutation(type="Planet", targetType="RootMutation2", args={
56+
* @GQL\Mutation(type="Planet", targetTypes="RootMutation2", args={
5757
* @GQL\Arg(type="PlanetInput!", name="planetInput")
5858
* })
5959
* @GQL\IsPublic("override_public")
@@ -64,23 +64,23 @@ public function createPlanetSchema2(array $planetInput): array
6464
}
6565

6666
/**
67-
* @GQL\Mutation(targetType={"RootMutation", "RootMutation2"})
67+
* @GQL\Mutation(targetTypes={"RootMutation", "RootMutation2"})
6868
*/
6969
public function destroyPlanet(int $planetId): bool
7070
{
7171
return true;
7272
}
7373

7474
/**
75-
* @GQL\Query(targetType={"RootQuery", "RootQuery2"})
75+
* @GQL\Query(targetTypes={"RootQuery", "RootQuery2"})
7676
*/
7777
public function isPlanetDestroyed(int $planetId): bool
7878
{
7979
return true;
8080
}
8181

8282
/**
83-
* @GQL\Query(targetType={"Droid", "Mandalorian"}, name="armorResistance")
83+
* @GQL\Query(targetTypes={"Droid", "Mandalorian"}, name="armorResistance")
8484
*/
8585
public function getArmorResistance(): int
8686
{

tests/Config/Parser/fixtures/annotations/Repository/WeaponRepository.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Overblog\GraphQLBundle\Annotation as GQL;
88

99
/**
10-
* @GQL\Provider(targetTypeQuery={"RootQuery2"}, targetTypeMutation="RootMutation2")
10+
* @GQL\Provider(targetQueryTypes={"RootQuery2"}, targetMutationTypes="RootMutation2")
1111
*/
1212
class WeaponRepository
1313
{
@@ -20,7 +20,7 @@ public function hasSecretWeapons(): bool
2020
}
2121

2222
/**
23-
* @GQL\Query(targetType="RootQuery")
23+
* @GQL\Query(targetTypes="RootQuery")
2424
*/
2525
public function countSecretWeapons(): int
2626
{

0 commit comments

Comments
 (0)