Skip to content

Commit 8495af2

Browse files
committed
Refactor GraphQL & extending documentations for clarity and accuracy
Updated terminology from "stages" to "providers and processors" for better clarity. Removed redundant sections to streamline information on custom mutations and configuration examples.
1 parent 060b4a6 commit 8495af2

File tree

2 files changed

+12
-173
lines changed

2 files changed

+12
-173
lines changed

core/extending.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ When using Symfony, the access checker provider is used at three different stage
6868

6969
Here is an example of the decoration of the RespondProcessor:
7070

71-
Starts by creating your `CustomRespondProcessor`:
71+
Starts by creating your `CustomRespondProcessor`:
72+
7273
```php
7374
<?php
7475
namespace App\State;

core/graphql.md

Lines changed: 10 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,12 @@ final class BookCollectionResolver implements QueryCollectionResolverInterface
409409
}
410410
```
411411

412-
### Custom Queries config for Symfony
412+
### Custom Queries config for Symfony
413413

414414
If you use autoconfiguration (the default Symfony configuration) in your application, then you are done!
415415

416416
Else, you need to tag your resolver like this if you using Symfony without autoconfiguration :
417417

418-
419418
```yaml
420419
# api/config/services.yaml
421420
services:
@@ -633,8 +632,8 @@ They are following the GraphQL type system.
633632
If you don't define the `args` property, it will be the default ones (for example `id` for an item).
634633
You can also use the `extraArgs` property if you want to add more arguments than the generated ones.
635634

636-
If you don't want API Platform to retrieve the item for you, disable the `read` stage like in `withDefaultArgsNotRetrievedQuery`.
637-
Some other stages [can be disabled](#disabling-resolver-stages).
635+
If you don't want API Platform to retrieve the item for you, disable the `read` provider.
636+
Some other providers and processors [can be disabled](#disabling-system-providers-and-processors).
638637
Another option would be to make sure there is no `id` argument.
639638
This is the case for `notRetrievedQuery` (empty args).
640639
Conversely, if you need to add custom arguments, make sure `id` is added among the arguments if you need the item to be retrieved automatically.
@@ -737,145 +736,17 @@ final class BookMutationResolver implements MutationResolverInterface
737736
```
738737

739738
As you can see, depending on how you configure your custom mutation in the resource, the item is retrieved or not.
740-
For instance, if you don't set an `id` argument or if you disable the `read` or the `deserialize` stage (other stages [can also be disabled](#disabling-resolver-stages)),
739+
For instance, if you don't set an `id` argument or if you disable the `read` or the `deserialize` providers (other state providers and state processors [can also be disabled](#disabling-system-providers-and-processors)),
741740
the received item will be `null`.
742741

743742
Likewise, if you don't want your item to be persisted by API Platform,
744-
you can return `null` instead of the mutated item (be careful: the response will also be `null`) or disable the `write` stage.
743+
you can return `null` instead of the mutated item (be careful: the response will also be `null`) or disable the `write` provider.
745744

746745
Don't forget the resolver is a service and you can inject the dependencies you want.
747746

748747
If you don't use autoconfiguration, add the tag `api_platform.graphql.mutation_resolver` to the resolver service.
749748
If you're using Laravel, don't forget to tag the resolver service with the `ApiPlatform\GraphQl\Resolver\MutationResolverInterface`.
750749

751-
Now in your resource:
752-
753-
<code-selector>
754-
755-
```php
756-
<?php
757-
// api/src/Entity/Book.php
758-
namespace App\Entity;
759-
760-
use ApiPlatform\Metadata\ApiResource;
761-
use ApiPlatform\Metadata\GraphQl\DeleteMutation;
762-
use ApiPlatform\Metadata\GraphQl\Mutation;
763-
use ApiPlatform\Metadata\GraphQl\Query;
764-
use ApiPlatform\Metadata\GraphQl\QueryCollection;
765-
use App\Resolver\BookMutationResolver;
766-
767-
#[ApiResource(
768-
graphQlOperations: [
769-
new Query(),
770-
new QueryCollection(),
771-
new Mutation(name: 'create'),
772-
new Mutation(name: 'update'),
773-
new DeleteMutation(name: 'delete'),
774-
775-
new Mutation(
776-
name: 'mutation',
777-
resolver: BookMutationResolver::class,
778-
extraArgs: ['id' => ['type' => 'ID!']]
779-
),
780-
new Mutation(
781-
name: 'withCustomArgsMutation',
782-
resolver: BookMutationResolver::class,
783-
args: [
784-
'sendMail' => [
785-
'type' => 'Boolean!',
786-
'description' => 'Send a mail?'
787-
]
788-
]
789-
),
790-
new Mutation(
791-
name: 'disabledStagesMutation',
792-
resolver: BookMutationResolver::class,
793-
deserialize: false,
794-
write: false
795-
)
796-
]
797-
)]
798-
class Book
799-
{
800-
// ...
801-
}
802-
```
803-
804-
```yaml
805-
#The YAML syntax is only supported for Symfony
806-
resources:
807-
App\Entity\Book:
808-
graphQlOperations:
809-
- class: ApiPlatform\Metadata\GraphQl\Query
810-
- class: ApiPlatform\Metadata\GraphQl\QueryCollection
811-
- class: ApiPlatform\Metadata\GraphQl\Mutation
812-
name: create
813-
- class: ApiPlatform\Metadata\GraphQl\Mutation
814-
name: update
815-
- class: ApiPlatform\Metadata\GraphQl\Mutation
816-
name: delete
817-
818-
- class: ApiPlatform\Metadata\GraphQl\Mutation
819-
name: mutation
820-
resolver: App\Resolver\BookMutationResolver
821-
extraArgs:
822-
id:
823-
type: 'ID!'
824-
- class: ApiPlatform\Metadata\GraphQl\Mutation
825-
name: withCustomArgsMutation
826-
resolver: App\Resolver\BookMutationResolver
827-
args:
828-
sendMail:
829-
type: 'Boolean!'
830-
description: 'Send a mail?'
831-
- class: ApiPlatform\Metadata\GraphQl\Mutation
832-
name: disabledStagesMutation
833-
resolver: App\Resolver\BookMutationResolver
834-
deserialize: false
835-
write: false
836-
```
837-
838-
```xml
839-
<!--The XML syntax is only supported for Symfony-->
840-
<resources xmlns="https://api-platform.com/schema/metadata/resources-3.0"
841-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
842-
xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0
843-
https://api-platform.com/schema/metadata/resources-3.0.xsd">
844-
<resource class="App\Entity\Book">
845-
<graphQlOperations>
846-
<graphQlOperation class="ApiPlatform\Metadata\GraphQl\Query" />
847-
<graphQlOperation class="ApiPlatform\Metadata\GraphQl\QueryCollection" />
848-
<graphQlOperation class="ApiPlatform\Metadata\GraphQl\Mutation" name="create" />
849-
<graphQlOperation class="ApiPlatform\Metadata\GraphQl\Mutation" name="update" />
850-
<graphQlOperation class="ApiPlatform\Metadata\GraphQl\Mutation" name="delete" />
851-
852-
<graphQlOperation class="ApiPlatform\Metadata\GraphQl\Mutation" name="mutation" resolver="App\Resolver\BookMutationResolver">
853-
<extraArgs>
854-
<arg id="id">
855-
<values>
856-
<value name="type">ID!</value>
857-
</values>
858-
</arg>
859-
</extraArgs>
860-
</graphQlOperation>
861-
<graphQlOperation class="ApiPlatform\Metadata\GraphQl\Mutation" name="withCustomArgsMutation" resolver="App\Resolver\BookMutationResolver">
862-
<args>
863-
<arg id="sendMail">
864-
<values>
865-
<value name="type">Boolean!</value>
866-
<value name="description">Send a mail?</value>
867-
</values>
868-
</arg>
869-
</args>
870-
</graphQlOperation>
871-
<graphQlOperation class="ApiPlatform\Metadata\GraphQl\Mutation" name="disabledStagesMutation" resolver="App\Resolver\BookMutationResolver" deserialize="false" write="false" />
872-
</graphQlOperations>
873-
</resource>
874-
</resources>
875-
```
876-
877-
</code-selector>
878-
879750
Note that you need to explicitly add the auto-generated queries and mutations if they are needed when configuring custom mutations, like it's done for the [operations](#operations).
880751

881752
As the custom queries, you can define your own arguments if you don't want to use the default ones (extracted from your resource).
@@ -884,38 +755,6 @@ You can also use the `extraArgs` property in case you need to add additional arg
884755

885756
The arguments will be in `$context['args']['input']` of your resolvers.
886757

887-
Your custom mutations will be available like this:
888-
889-
```graphql
890-
{
891-
mutation {
892-
mutationBook(input: {id: "/books/18", title: "The Fitz and the Fool"}) {
893-
book {
894-
title
895-
}
896-
}
897-
}
898-
899-
mutation {
900-
withCustomArgsMutationBook(input: {sendMail: true, clientMutationId: "myId"}) {
901-
book {
902-
title
903-
}
904-
clientMutationId
905-
}
906-
}
907-
908-
mutation {
909-
disabledStagesMutationBook(input: {title: "The Fitz and the Fool"}) {
910-
book {
911-
title
912-
}
913-
clientMutationId
914-
}
915-
}
916-
}
917-
```
918-
919758
## Subscriptions
920759

921760
Subscriptions are an [RFC](https://github.com/graphql/graphql-spec/blob/master/rfcs/Subscriptions.md#rfc-graphql-subscriptions) to allow a client to receive pushed realtime data from the server.
@@ -1043,9 +882,9 @@ See the [Extending API Platform](extending.md) documentation for more informatio
1043882

1044883
### Disabling system providers and processors
1045884

1046-
If you need to, you can disable some stages done by the resolvers, for instance if you don't want your data to be validated.
885+
If you need to, you can disable some states providers and state processors done by the resolvers, for instance if you don't want your data to be validated.
1047886

1048-
The following table lists the stages you can disable in your resource configuration.
887+
The following table lists the system states providers and states processors you can disable in your resource configuration.
1049888

1050889
| Attribute | Type | Default | Description |
1051890
|----------------------------|--------|---------|-------------------------------------------|
@@ -2760,8 +2599,7 @@ You can also check the documentation of [graphql-php](https://webonyx.github.io/
27602599
The big difference in API Platform is that the value is already serialized when it's received in your type class.
27612600
Similarly, you would not want to denormalize your parsed value since it will be done by API Platform later.
27622601

2763-
2764-
#### Custom Types config for Symfony
2602+
### Custom Types config for Symfony
27652603

27662604
If you use autoconfiguration (the default Symfony configuration) in your application, then you are done!
27672605

@@ -2781,7 +2619,7 @@ Your custom type is now registered and is available in the `TypesContainer`.
27812619
To use it please [modify the extracted types](#modify-the-extracted-types) or use it directly in [custom queries](#custom-queries) or [custom mutations](#custom-mutations).
27822620

27832621

2784-
#### Custom Types config for Laravel
2622+
### Custom Types config for Laravel
27852623

27862624
If you are using Laravel tag your type with:
27872625

@@ -2928,7 +2766,7 @@ final class BookContextBuilder implements SerializerContextBuilderInterface
29282766
}
29292767
```
29302768

2931-
## Export the Schema in SDL
2769+
## Export the Schema in SDL
29322770

29332771
> [!WARNING]
29342772
> These commands are only available for API Platform with Symfony!

0 commit comments

Comments
 (0)