Skip to content

Commit c353e5a

Browse files
jotweajosef.wagner
andauthored
fix(graphql): do not add id field if operation already has a dedicated input type (#5095)
Co-authored-by: josef.wagner <josef.wagner@hf-solutions.co>
1 parent 7a78fbe commit c353e5a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/GraphQl/Type/FieldsBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function getResourceObjectTypeFields(?string $resourceClass, Operation $o
195195
return $fields;
196196
}
197197

198-
if (!$input || 'create' !== $operation->getName()) {
198+
if (!$input || ('create' !== $operation->getName() && !$operation->getInput())) {
199199
$fields['id'] = $idField;
200200
}
201201
if ($input && $depth >= 1) {

tests/GraphQl/Type/FieldsBuilderTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,31 @@ public function resourceObjectTypeFieldsProvider(): array
697697
'clientMutationId' => GraphQLType::string(),
698698
],
699699
],
700+
'mutation using input DTO' => ['resourceClass', (new Mutation())->withName('mutation')->withInput(GraphQLType::string()),
701+
[
702+
'property' => new ApiProperty(),
703+
'propertyBool' => (new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_BOOL)])->withDescription('propertyBool description')->withReadable(false)->withWritable(true)->withDeprecationReason('not useful'),
704+
'propertySubresource' => (new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_BOOL)])->withReadable(false)->withWritable(true),
705+
],
706+
true, 0, null,
707+
[
708+
'propertyBool' => [
709+
'type' => GraphQLType::nonNull(GraphQLType::string()),
710+
'description' => 'propertyBool description',
711+
'args' => [],
712+
'resolve' => null,
713+
'deprecationReason' => 'not useful',
714+
],
715+
'propertySubresource' => [
716+
'type' => GraphQLType::nonNull(GraphQLType::string()),
717+
'description' => null,
718+
'args' => [],
719+
'resolve' => null,
720+
'deprecationReason' => null,
721+
],
722+
'clientMutationId' => GraphQLType::string(),
723+
],
724+
],
700725
'mutation nested input' => ['resourceClass', (new Mutation())->withClass('resourceClass')->withName('mutation'),
701726
[
702727
'propertyBool' => (new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_BOOL)])->withReadable(false)->withWritable(true),

0 commit comments

Comments
 (0)