Skip to content

Update graphql.md #1347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 40 additions & 22 deletions core/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,28 +288,35 @@ use App\Resolver\BookResolver;

#[ApiResource(
graphql: [
'retrievedQuery' => [
'item_query' => BookResolver::class
],
'notRetrievedQuery' => [
'item_query' => BookResolver::class,
'args' => []
],
'withDefaultArgsNotRetrievedQuery' => [
'item_query' => BookResolver::class,
'read' => false
],
'withCustomArgsQuery' => [
'item_query' => BookResolver::class,
'args' => [
'id' => ['type' => 'ID!'],
'log' => ['type' => 'Boolean!', 'description' => 'Is logging activated?'],
'logDate' => ['type' => 'DateTime']
]
],
'collectionQuery' => [
'collection_query' => BookCollectionResolver::class
]
// Auto-generated queries and mutations
'item_query',
'collection_query',
'create',
'update',
'delete',

'retrievedQuery' => [
'item_query' => BookResolver::class
],
'notRetrievedQuery' => [
'item_query' => BookResolver::class,
'args' => []
],
'withDefaultArgsNotRetrievedQuery' => [
'item_query' => BookResolver::class,
'read' => false
],
'withCustomArgsQuery' => [
'item_query' => BookResolver::class,
'args' => [
'id' => ['type' => 'ID!'],
'log' => ['type' => 'Boolean!', 'description' => 'Is logging activated?'],
'logDate' => ['type' => 'DateTime']
]
],
'collectionQuery' => [
'collection_query' => BookCollectionResolver::class
]
]
)]
class Book
Expand All @@ -318,6 +325,8 @@ class Book
}
```

Note that you need to explicitly add the auto-generated queries and mutations if they are needed when configuring custom queries, like it's done for the [operations](#operations).

As you can see, it's possible to define your own arguments for your custom queries.
They are following the GraphQL type system.
If you don't define the `args` property, it will be the default ones (for example `id` for an item).
Expand Down Expand Up @@ -445,6 +454,13 @@ use App\Resolver\BookMutationResolver;

#[ApiResource(
graphql: [
// Auto-generated queries and mutations
'item_query',
'collection_query',
'create',
'update',
'delete',

'mutation' => [
'mutation' => BookMutationResolver::class
],
Expand All @@ -467,6 +483,8 @@ class Book
}
```

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).

As the custom queries, you can define your own arguments if you don't want to use the default ones (extracted from your resource).
The only difference with them is that, even if you define your own arguments, the `clientMutationId` will always be set.

Expand Down