Description
Setting description: on a GraphQL Mutation (or DeleteMutation) has no effect: the SDL always shows the generated "Creates a X." text. Query/QueryCollection are not affected — an explicit description on a query is preserved, so mutations behave inconsistently.
Minimal reproduction
#[ApiResource(graphQlOperations: [
new Mutation(name: 'create', description: 'My custom description.'),
])]
class Book
{
}
Resulting SDL:
type Mutation {
"""Creates a Book."""
createBook(input: createBookInput!): createBookPayload
}
Expected:
type Mutation {
"""My custom description."""
createBook(input: createBookInput!): createBookPayload
}
Root cause
OperationDefaultsTrait::getOperationWithDefaults() overwrites the description of every mutation unconditionally:
https://github.com/api-platform/core/blob/4.3/src/Metadata/Resource/Factory/OperationDefaultsTrait.php#L205-L207
if ($operation instanceof Mutation) {
$operation = $operation->withDescription(ucfirst("{$operation->getName()}s a {$resource->getShortName()}."));
}
There is no null-check, so a user-provided description is discarded.
Regression
The generated text was introduced in #3477 as a fallback only — "a custom value takes precedence; it does not overwrite existing descriptions". A later refactoring that moved this logic into OperationDefaultsTrait dropped the null-check.
This was reported before in #6035, which was closed as stale without a fix.
Versions
Reproduced with api-platform/metadata v4.2.15; the code is still present on 4.3 and main.
Expected behavior
An explicitly provided description is preserved; the generated "{name}s a {ShortName}." text is only a fallback when none is set.
Description
Setting
description:on a GraphQLMutation(orDeleteMutation) has no effect: the SDL always shows the generated"Creates a X."text.Query/QueryCollectionare not affected — an explicit description on a query is preserved, so mutations behave inconsistently.Minimal reproduction
#[ApiResource(graphQlOperations: [ new Mutation(name: 'create', description: 'My custom description.'), ])] class Book { }Resulting SDL:
Expected:
Root cause
OperationDefaultsTrait::getOperationWithDefaults()overwrites the description of every mutation unconditionally:https://github.com/api-platform/core/blob/4.3/src/Metadata/Resource/Factory/OperationDefaultsTrait.php#L205-L207
There is no null-check, so a user-provided description is discarded.
Regression
The generated text was introduced in #3477 as a fallback only — "a custom value takes precedence; it does not overwrite existing descriptions". A later refactoring that moved this logic into
OperationDefaultsTraitdropped the null-check.This was reported before in #6035, which was closed as stale without a fix.
Versions
Reproduced with api-platform/metadata v4.2.15; the code is still present on
4.3andmain.Expected behavior
An explicitly provided description is preserved; the generated
"{name}s a {ShortName}."text is only a fallback when none is set.