Skip to content

Commit 8fde8f1

Browse files
authored
[GraphQL] Mutations have description field (#3477)
1 parent e1e18d4 commit 8fde8f1

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/GraphQl/Type/FieldsBuilder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ public function getMutationFields(string $resourceClass, ResourceMetadata $resou
135135
$mutationFields = [];
136136
$shortName = $resourceMetadata->getShortName();
137137
$resourceType = new Type(Type::BUILTIN_TYPE_OBJECT, true, $resourceClass);
138+
$description = $resourceMetadata->getGraphqlAttribute($mutationName, 'description', ucfirst("{$mutationName}s a $shortName."), false);
138139
$deprecationReason = $resourceMetadata->getGraphqlAttribute($mutationName, 'deprecation_reason', '', true);
139140

140-
if ($fieldConfiguration = $this->getResourceFieldConfiguration(null, ucfirst("{$mutationName}s a $shortName."), $deprecationReason, $resourceType, $resourceClass, false, null, $mutationName, null)) {
141+
if ($fieldConfiguration = $this->getResourceFieldConfiguration(null, $description, $deprecationReason, $resourceType, $resourceClass, false, null, $mutationName, null)) {
141142
$fieldConfiguration['args'] += ['input' => $this->getResourceFieldConfiguration(null, null, $deprecationReason, $resourceType, $resourceClass, true, null, $mutationName, null)];
142143
}
143144

@@ -154,9 +155,10 @@ public function getSubscriptionFields(string $resourceClass, ResourceMetadata $r
154155
$subscriptionFields = [];
155156
$shortName = $resourceMetadata->getShortName();
156157
$resourceType = new Type(Type::BUILTIN_TYPE_OBJECT, true, $resourceClass);
158+
$description = $resourceMetadata->getGraphqlAttribute($subscriptionName, 'description', "Subscribes to the $subscriptionName event of a $shortName.", false);
157159
$deprecationReason = $resourceMetadata->getGraphqlAttribute($subscriptionName, 'deprecation_reason', '', true);
158160

159-
if ($fieldConfiguration = $this->getResourceFieldConfiguration(null, "Subscribes to the $subscriptionName event of a $shortName.", $deprecationReason, $resourceType, $resourceClass, false, null, null, $subscriptionName)) {
161+
if ($fieldConfiguration = $this->getResourceFieldConfiguration(null, $description, $deprecationReason, $resourceType, $resourceClass, false, null, null, $subscriptionName)) {
160162
$fieldConfiguration['args'] += ['input' => $this->getResourceFieldConfiguration(null, null, $deprecationReason, $resourceType, $resourceClass, true, null, null, $subscriptionName)];
161163
}
162164

tests/GraphQl/Type/FieldsBuilderTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,26 @@ public function mutationFieldsProvider(): array
393393
],
394394
],
395395
],
396+
'custom description' => ['resourceClass', (new ResourceMetadata('ShortName'))->withGraphql(['action' => ['description' => 'Custom description.']]), 'action', $graphqlType = new ObjectType(['name' => 'mutation']), $inputGraphqlType = new ObjectType(['name' => 'input']), $mutationResolver = function () {
397+
},
398+
[
399+
'actionShortName' => [
400+
'type' => $graphqlType,
401+
'description' => 'Custom description.',
402+
'args' => [
403+
'input' => [
404+
'type' => $inputGraphqlType,
405+
'description' => null,
406+
'args' => [],
407+
'resolve' => null,
408+
'deprecationReason' => '',
409+
],
410+
],
411+
'resolve' => $mutationResolver,
412+
'deprecationReason' => '',
413+
],
414+
],
415+
],
396416
];
397417
}
398418

@@ -438,6 +458,26 @@ public function subscriptionFieldsProvider(): array
438458
],
439459
],
440460
],
461+
'custom description' => ['resourceClass', (new ResourceMetadata('ShortName'))->withAttributes(['mercure' => true])->withGraphql(['action' => ['description' => 'Custom description.']]), 'action', $graphqlType = new ObjectType(['name' => 'subscription']), $inputGraphqlType = new ObjectType(['name' => 'input']), $subscriptionResolver = function () {
462+
},
463+
[
464+
'actionShortNameSubscribe' => [
465+
'type' => $graphqlType,
466+
'description' => 'Custom description.',
467+
'args' => [
468+
'input' => [
469+
'type' => $inputGraphqlType,
470+
'description' => null,
471+
'args' => [],
472+
'resolve' => null,
473+
'deprecationReason' => '',
474+
],
475+
],
476+
'resolve' => $subscriptionResolver,
477+
'deprecationReason' => '',
478+
],
479+
],
480+
],
441481
];
442482
}
443483

0 commit comments

Comments
 (0)