Skip to content

Commit 41cacb2

Browse files
authored
fix(graphql): replace Mutation with DeleteMutation (#1669)
1 parent c9bc7ab commit 41cacb2

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

core/graphql.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ api_platform:
133133

134134
To understand what an operation is, please refer to the [operations documentation](operations.md).
135135

136-
For GraphQL, the operations are defined by using the `Query`, `QueryCollection`, `Mutation` and `Subscription` attributes.
136+
For GraphQL, the operations are defined by using the `Query`, `QueryCollection`, `Mutation`, `DeleteMutation` and `Subscription` attributes.
137137

138138
By default, the following operations are enabled:
139139

140140
* `Query`
141141
* `QueryCollection`
142142
* `Mutation(name: 'create')`
143143
* `Mutation(name: 'update')`
144-
* `Mutation(name: 'delete')`
144+
* `DeleteMutation(name: 'delete')`
145145

146146
You can of course disable or configure these operations.
147147

@@ -283,6 +283,7 @@ In your resource, add the following:
283283
namespace App\Entity;
284284
285285
use ApiPlatform\Metadata\ApiResource;
286+
use ApiPlatform\Metadata\GraphQl\DeleteMutation;
286287
use ApiPlatform\Metadata\GraphQl\Mutation;
287288
use ApiPlatform\Metadata\GraphQl\Query;
288289
use ApiPlatform\Metadata\GraphQl\QueryCollection;
@@ -294,7 +295,7 @@ use App\Resolver\BookResolver;
294295
new QueryCollection(),
295296
new Mutation(name: 'create'),
296297
new Mutation(name: 'update'),
297-
new Mutation(name: 'delete'),
298+
new DeleteMutation(name: 'delete'),
298299
299300
new Query(name: 'retrievedQuery', resolver: BookResolver::class),
300301
new Query(
@@ -377,7 +378,10 @@ You custom queries will be available like this:
377378

378379
If you don't know what mutations are yet, the documentation about them is [here](https://graphql.org/learn/queries/#mutations).
379380

380-
For each resource, three mutations are available: one for creating it (`create`), one for updating it (`update`) and one for deleting it (`delete`).
381+
For each resource, three mutations are available:
382+
* `Mutation(name: 'create')` for creating a new resource
383+
* `Mutation(name: 'update')` for updating an existing resource
384+
* `DeleteMutation(name: 'delete')` for deleting an existing resource
381385

382386
When updating or deleting a resource, you need to pass the **IRI** of the resource as argument. See [Global Object Identifier](#global-object-identifier) for more information.
383387

@@ -449,6 +453,7 @@ Now in your resource:
449453
namespace App\Entity;
450454
451455
use ApiPlatform\Metadata\ApiResource;
456+
use ApiPlatform\Metadata\GraphQl\DeleteMutation;
452457
use ApiPlatform\Metadata\GraphQl\Mutation;
453458
use ApiPlatform\Metadata\GraphQl\Query;
454459
use ApiPlatform\Metadata\GraphQl\QueryCollection;
@@ -460,7 +465,7 @@ use App\Resolver\BookMutationResolver;
460465
new QueryCollection(),
461466
new Mutation(name: 'create'),
462467
new Mutation(name: 'update'),
463-
new Mutation(name: 'delete'),
468+
new DeleteMutation(name: 'delete'),
464469
465470
new Mutation(name: 'mutation', resolver: BookMutationResolver::class),
466471
new Mutation(
@@ -747,7 +752,7 @@ Filters are supported out-of-the-box. Follow the [filters](filters.md) documenta
747752
However you don't necessarily have the same needs for your GraphQL endpoint as for your REST one.
748753

749754
In the `QueryCollection` attribute, you can choose to decorrelate the GraphQL filters.
750-
In order to keep the default behavior (possibility to fetch, delete, update or create), define all the auto-generated operations (`Query` ,`QueryCollection`, and the `delete`, `update` and `create` `Mutation`).
755+
In order to keep the default behavior (possibility to fetch, delete, update or create), define all the auto-generated operations (`Query` ,`QueryCollection`, `DeleteMutation`, and the `update` and `create` `Mutation`).
751756

752757
For example, this entity will have a search filter for REST and a date filter for GraphQL:
753758

@@ -757,6 +762,7 @@ For example, this entity will have a search filter for REST and a date filter fo
757762
namespace App\Entity;
758763
759764
use ApiPlatform\Metadata\ApiResource;
765+
use ApiPlatform\Metadata\GraphQl\DeleteMutation;
760766
use ApiPlatform\Metadata\GraphQl\Mutation;
761767
use ApiPlatform\Metadata\GraphQl\Query;
762768
use ApiPlatform\Metadata\GraphQl\QueryCollection;
@@ -766,7 +772,7 @@ use ApiPlatform\Metadata\GraphQl\QueryCollection;
766772
new QueryCollection(filters: ['offer.date_filter']),
767773
new Mutation(name: 'create'),
768774
new Mutation(name: 'update'),
769-
new Mutation(name: 'delete')
775+
new DeleteMutation(name: 'delete')
770776
])]
771777
class Offer
772778
{
@@ -970,6 +976,7 @@ For instance at the operation level:
970976
namespace App\Entity;
971977
972978
use ApiPlatform\Metadata\ApiResource;
979+
use ApiPlatform\Metadata\GraphQl\DeleteMutation;
973980
use ApiPlatform\Metadata\GraphQl\Mutation;
974981
use ApiPlatform\Metadata\GraphQl\Query;
975982
use ApiPlatform\Metadata\GraphQl\QueryCollection;
@@ -979,7 +986,7 @@ use ApiPlatform\Metadata\GraphQl\QueryCollection;
979986
new QueryCollection(paginationType: 'page'),
980987
new Mutation(name: 'create'),
981988
new Mutation(name: 'update'),
982-
new Mutation(name: 'delete')
989+
new DeleteMutation(name: 'delete')
983990
])]
984991
class Offer
985992
{
@@ -1108,6 +1115,7 @@ namespace App\Entity;
11081115
11091116
use ApiPlatform\Metadata\ApiResource;
11101117
use ApiPlatform\Metadata\Get;
1118+
use ApiPlatform\Metadata\GraphQl\DeleteMutation;
11111119
use ApiPlatform\Metadata\GraphQl\Mutation;
11121120
use ApiPlatform\Metadata\GraphQl\Query;
11131121
use ApiPlatform\Metadata\GraphQl\QueryCollection;
@@ -1122,7 +1130,7 @@ use ApiPlatform\Metadata\Post;
11221130
graphQlOperations: [
11231131
new Query(security: "is_granted('ROLE_USER') and object.owner == user"),
11241132
new QueryCollection(security: "is_granted('ROLE_ADMIN')"),
1125-
new Mutation(name: 'delete', security: "is_granted('ROLE_ADMIN')"),
1133+
new DeleteMutation(name: 'delete', security: "is_granted('ROLE_ADMIN')"),
11261134
new Mutation(name: 'create', security: "is_granted('ROLE_ADMIN')")
11271135
]
11281136
)]

0 commit comments

Comments
 (0)