You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/graphql.md
+17-9Lines changed: 17 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,15 +133,15 @@ api_platform:
133
133
134
134
To understand what an operation is, please refer to the [operations documentation](operations.md).
135
135
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.
137
137
138
138
By default, the following operations are enabled:
139
139
140
140
* `Query`
141
141
* `QueryCollection`
142
142
* `Mutation(name: 'create')`
143
143
* `Mutation(name: 'update')`
144
-
* `Mutation(name: 'delete')`
144
+
* `DeleteMutation(name: 'delete')`
145
145
146
146
You can of course disable or configure these operations.
147
147
@@ -283,6 +283,7 @@ In your resource, add the following:
283
283
namespace App\Entity;
284
284
285
285
use ApiPlatform\Metadata\ApiResource;
286
+
use ApiPlatform\Metadata\GraphQl\DeleteMutation;
286
287
use ApiPlatform\Metadata\GraphQl\Mutation;
287
288
use ApiPlatform\Metadata\GraphQl\Query;
288
289
use ApiPlatform\Metadata\GraphQl\QueryCollection;
@@ -294,7 +295,7 @@ use App\Resolver\BookResolver;
294
295
new QueryCollection(),
295
296
new Mutation(name: 'create'),
296
297
new Mutation(name: 'update'),
297
-
new Mutation(name: 'delete'),
298
+
new DeleteMutation(name: 'delete'),
298
299
299
300
new Query(name: 'retrievedQuery', resolver: BookResolver::class),
300
301
new Query(
@@ -377,7 +378,10 @@ You custom queries will be available like this:
377
378
378
379
If you don't know what mutations are yet, the documentation about them is [here](https://graphql.org/learn/queries/#mutations).
379
380
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
381
385
382
386
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.
383
387
@@ -449,6 +453,7 @@ Now in your resource:
449
453
namespace App\Entity;
450
454
451
455
use ApiPlatform\Metadata\ApiResource;
456
+
use ApiPlatform\Metadata\GraphQl\DeleteMutation;
452
457
use ApiPlatform\Metadata\GraphQl\Mutation;
453
458
use ApiPlatform\Metadata\GraphQl\Query;
454
459
use ApiPlatform\Metadata\GraphQl\QueryCollection;
@@ -460,7 +465,7 @@ use App\Resolver\BookMutationResolver;
460
465
new QueryCollection(),
461
466
new Mutation(name: 'create'),
462
467
new Mutation(name: 'update'),
463
-
new Mutation(name: 'delete'),
468
+
new DeleteMutation(name: 'delete'),
464
469
465
470
new Mutation(name: 'mutation', resolver: BookMutationResolver::class),
466
471
new Mutation(
@@ -747,7 +752,7 @@ Filters are supported out-of-the-box. Follow the [filters](filters.md) documenta
747
752
However you don't necessarily have the same needs for your GraphQL endpoint as for your REST one.
748
753
749
754
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`).
751
756
752
757
For example, this entity will have a search filter for REST and a date filter for GraphQL:
753
758
@@ -757,6 +762,7 @@ For example, this entity will have a search filter for REST and a date filter fo
757
762
namespace App\Entity;
758
763
759
764
use ApiPlatform\Metadata\ApiResource;
765
+
use ApiPlatform\Metadata\GraphQl\DeleteMutation;
760
766
use ApiPlatform\Metadata\GraphQl\Mutation;
761
767
use ApiPlatform\Metadata\GraphQl\Query;
762
768
use ApiPlatform\Metadata\GraphQl\QueryCollection;
@@ -766,7 +772,7 @@ use ApiPlatform\Metadata\GraphQl\QueryCollection;
766
772
new QueryCollection(filters: ['offer.date_filter']),
767
773
new Mutation(name: 'create'),
768
774
new Mutation(name: 'update'),
769
-
new Mutation(name: 'delete')
775
+
new DeleteMutation(name: 'delete')
770
776
])]
771
777
class Offer
772
778
{
@@ -970,6 +976,7 @@ For instance at the operation level:
970
976
namespace App\Entity;
971
977
972
978
use ApiPlatform\Metadata\ApiResource;
979
+
use ApiPlatform\Metadata\GraphQl\DeleteMutation;
973
980
use ApiPlatform\Metadata\GraphQl\Mutation;
974
981
use ApiPlatform\Metadata\GraphQl\Query;
975
982
use ApiPlatform\Metadata\GraphQl\QueryCollection;
@@ -979,7 +986,7 @@ use ApiPlatform\Metadata\GraphQl\QueryCollection;
979
986
new QueryCollection(paginationType: 'page'),
980
987
new Mutation(name: 'create'),
981
988
new Mutation(name: 'update'),
982
-
new Mutation(name: 'delete')
989
+
new DeleteMutation(name: 'delete')
983
990
])]
984
991
class Offer
985
992
{
@@ -1108,6 +1115,7 @@ namespace App\Entity;
1108
1115
1109
1116
use ApiPlatform\Metadata\ApiResource;
1110
1117
use ApiPlatform\Metadata\Get;
1118
+
use ApiPlatform\Metadata\GraphQl\DeleteMutation;
1111
1119
use ApiPlatform\Metadata\GraphQl\Mutation;
1112
1120
use ApiPlatform\Metadata\GraphQl\Query;
1113
1121
use ApiPlatform\Metadata\GraphQl\QueryCollection;
@@ -1122,7 +1130,7 @@ use ApiPlatform\Metadata\Post;
1122
1130
graphQlOperations: [
1123
1131
new Query(security: "is_granted('ROLE_USER') and object.owner == user"),
1124
1132
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')"),
1126
1134
new Mutation(name: 'create', security: "is_granted('ROLE_ADMIN')")
0 commit comments