Skip to content

Commit c30e42a

Browse files
jamesisaacalanpoulain
authored andcommitted
Allow non-writeable fields in mutation response (#2193)
1 parent fc55edd commit c30e42a

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

features/graphql/introspection.feature

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,10 @@ Feature: GraphQL introspection support
304304
And the JSON node "data.typeCreateInput.inputFields[0].name" should be equal to "bar"
305305
And the JSON node "data.typeCreateInput.inputFields[1].name" should be equal to "baz"
306306
And the JSON node "data.typeCreateInput.inputFields[2].name" should be equal to "clientMutationId"
307-
And the JSON node "data.typeCreatePayload.fields" should have 4 elements
307+
And the JSON node "data.typeCreatePayload.fields" should have 3 elements
308308
And the JSON node "data.typeCreatePayload.fields[0].name" should be equal to "id"
309309
And the JSON node "data.typeCreatePayload.fields[1].name" should be equal to "bar"
310-
And the JSON node "data.typeCreatePayload.fields[2].name" should be equal to "baz"
311-
And the JSON node "data.typeCreatePayload.fields[3].name" should be equal to "clientMutationId"
310+
And the JSON node "data.typeCreatePayload.fields[2].name" should be equal to "clientMutationId"
312311

313312
Scenario: Retrieve an item through a GraphQL query
314313
Given there are 4 dummy objects with relatedDummy

features/graphql/mutation.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Feature: GraphQL mutation support
4040
mutation {
4141
createFoo(input: {name: "A new one", bar: "new", clientMutationId: "myId"}) {
4242
id
43+
_id
4344
name
4445
bar
4546
clientMutationId
@@ -50,6 +51,7 @@ Feature: GraphQL mutation support
5051
And the response should be in JSON
5152
And the header "Content-Type" should be equal to "application/json"
5253
And the JSON node "data.createFoo.id" should be equal to "/foos/1"
54+
And the JSON node "data.createFoo._id" should be equal to 1
5355
And the JSON node "data.createFoo.name" should be equal to "A new one"
5456
And the JSON node "data.createFoo.bar" should be equal to "new"
5557
And the JSON node "data.createFoo.clientMutationId" should be equal to "myId"
@@ -272,7 +274,6 @@ Feature: GraphQL mutation support
272274
createDummyGroup(input: {bar: "Bar", baz: "Baz", clientMutationId: "myId"}) {
273275
id
274276
bar
275-
baz
276277
clientMutationId
277278
}
278279
}
@@ -282,7 +283,6 @@ Feature: GraphQL mutation support
282283
And the header "Content-Type" should be equal to "application/json"
283284
And the JSON node "data.createDummyGroup.id" should be equal to "/dummy_groups/2"
284285
And the JSON node "data.createDummyGroup.bar" should be equal to "Bar"
285-
And the JSON node "data.createDummyGroup.baz" should be null
286286
And the JSON node "data.createDummyGroup.clientMutationId" should be equal to "myId"
287287

288288
Scenario: Trigger a validation error

src/GraphQl/Type/SchemaBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ private function getResourceObjectTypeFields(?string $resourceClass, ResourceMet
459459
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $property, ['graphql_operation_name' => $mutationName ?? 'query']);
460460
if (
461461
null === ($propertyType = $propertyMetadata->getType())
462-
|| (!$input && null === $mutationName && false === $propertyMetadata->isReadable())
463-
|| (null !== $mutationName && false === $propertyMetadata->isWritable())
462+
|| (!$input && false === $propertyMetadata->isReadable())
463+
|| ($input && null !== $mutationName && false === $propertyMetadata->isWritable())
464464
) {
465465
continue;
466466
}

0 commit comments

Comments
 (0)