Skip to content

Commit bb2cdcd

Browse files
authored
feat(graphql): add extra args in the docs (#1705)
1 parent 2482b4d commit bb2cdcd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

core/graphql.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ Note that you need to explicitly add the auto-generated queries and mutations if
330330
As you can see, it's possible to define your own arguments for your custom queries.
331331
They are following the GraphQL type system.
332332
If you don't define the `args` property, it will be the default ones (for example `id` for an item).
333+
You can also use the `extraArgs` property if you want to add more arguments than the generated ones.
333334

334335
If you don't want API Platform to retrieve the item for you, disable the `read` stage like in `withDefaultArgsNotRetrievedQuery`.
335336
Some other stages [can be disabled](#disabling-resolver-stages).
@@ -344,7 +345,7 @@ Note also that:
344345

345346
The arguments you have defined or the default ones and their value will be in `$context['args']` of your resolvers.
346347

347-
You custom queries will be available like this:
348+
Your custom queries will be available like this:
348349

349350
```graphql
350351
{
@@ -467,7 +468,11 @@ use App\Resolver\BookMutationResolver;
467468
new Mutation(name: 'update'),
468469
new DeleteMutation(name: 'delete'),
469470
470-
new Mutation(name: 'mutation', resolver: BookMutationResolver::class),
471+
new Mutation(
472+
name: 'mutation',
473+
resolver: BookMutationResolver::class,
474+
extraArgs: ['id' => ['type' => 'ID!']]
475+
),
471476
new Mutation(
472477
name: 'withCustomArgsMutation',
473478
resolver: BookMutationResolver::class,
@@ -496,6 +501,7 @@ Note that you need to explicitly add the auto-generated queries and mutations if
496501

497502
As the custom queries, you can define your own arguments if you don't want to use the default ones (extracted from your resource).
498503
The only difference with them is that, even if you define your own arguments, the `clientMutationId` will always be set.
504+
You can also use the `extraArgs` property in case you need to add additional arguments (for instance to add the `id` argument since it is not added by default for a custom mutation).
499505

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

@@ -521,7 +527,7 @@ Your custom mutations will be available like this:
521527
}
522528
523529
mutation {
524-
disabledStagesMutationBook(input: {id: "/books/18", title: "The Fitz and the Fool"}) {
530+
disabledStagesMutationBook(input: {title: "The Fitz and the Fool"}) {
525531
book {
526532
title
527533
}

0 commit comments

Comments
 (0)