Skip to content

Commit a52c25e

Browse files
committed
Fix and test create support
1 parent f675f77 commit a52c25e

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

features/graphql/mutation.feature

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ Feature: GraphQL mutation support
9191
And the JSON node "data.updateDummy.name" should be equal to "Dummy #1"
9292
And the JSON node "data.updateDummy.description" should be equal to "Modified description."
9393

94-
@dropSchema
9594
# @TODO Find a way to manage composite identifiers.
9695
Scenario: Modify an item with composite identifiers through a mutation
9796
Given there are Composite identifier objects
@@ -115,3 +114,24 @@ Feature: GraphQL mutation support
115114
#And the JSON node "data.putCompositeRelation.compositeItem.id" should be equal to 1
116115
#And the JSON node "data.putCompositeRelation.compositeLabel.id" should be equal to 1
117116
#And the JSON node "data.putCompositeRelation.value" should be equal to "Modified value."
117+
118+
@dropSchema
119+
Scenario: Create an item
120+
When I send the following GraphQL request:
121+
"""
122+
mutation {
123+
createDummy(input: {name: "A new one", alias: "new", description: "brand new!"}) {
124+
id,
125+
name,
126+
alias,
127+
description
128+
}
129+
}
130+
"""
131+
Then the response status code should be 200
132+
And the response should be in JSON
133+
And the header "Content-Type" should be equal to "application/json"
134+
And the JSON node "data.createDummy.id" should be equal to 2
135+
And the JSON node "data.createDummy.name" should be equal to "A new one"
136+
And the JSON node "data.createDummy.alias" should be equal to "new"
137+
And the JSON node "data.createDummy.description" should be equal to "brand new!"

src/Bridge/Graphql/Resolver/ItemMutationResolverFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ public function __construct(IdentifiersExtractorInterface $identifiersExtractor,
4848
public function createItemMutationResolver(string $resourceClass, string $mutationName): callable
4949
{
5050
return function ($root, $args, $context, ResolveInfo $info) use ($resourceClass, $mutationName) {
51-
$id = $this->getIdentifier($this->identifiersExtractor->getIdentifiersFromResourceClass($resourceClass), $args, $info);
5251
$item = null;
53-
5452
if ('update' === $mutationName || 'delete' === $mutationName) {
53+
$id = $this->getIdentifier($this->identifiersExtractor->getIdentifiersFromResourceClass($resourceClass), $args, $info);
5554
$item = $this->getItem($resourceClass, $id, $info);
5655
}
5756

src/Bridge/Graphql/Type/SchemaBuilder.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,13 @@ private function getResourceObjectTypeFields(string $resource, bool $isInput = f
287287
$fields = [];
288288
foreach ($this->propertyNameCollectionFactory->create($resource) as $property) {
289289
$propertyMetadata = $this->propertyMetadataFactory->create($resource, $property);
290-
if (null === ($propertyType = $propertyMetadata->getType())
291-
|| !$propertyMetadata->isReadable()
292-
|| ($isMutation && 'delete' === $mutationName && !$propertyMetadata->isIdentifier())) {
290+
if (
291+
null === ($propertyType = $propertyMetadata->getType())
292+
|| (!$isInput && !$isMutation && !$propertyMetadata->isReadable())
293+
//|| ($isMutation && !$propertyMetadata->isWritable())
294+
|| ($isInput && $isMutation && 'create' === $mutationName && $propertyMetadata->isIdentifier())
295+
|| ($isMutation && 'delete' === $mutationName && !$propertyMetadata->isIdentifier())
296+
) {
293297
continue;
294298
}
295299

src/Metadata/Resource/Factory/OperationResourceMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function create(string $resourceClass): ResourceMetadata
8484

8585
$graphql = $resourceMetadata->getGraphql();
8686
if (null === $graphql) {
87-
$resourceMetadata = $resourceMetadata->withGraphql(['query' => [], 'delete' => [], 'update' => []]);
87+
$resourceMetadata = $resourceMetadata->withGraphql(['query' => [], 'delete' => [], 'update' => [], 'create' => []]);
8888
} else {
8989
$resourceMetadata = $this->normalizeGraphQl($resourceMetadata, $graphql);
9090
}

0 commit comments

Comments
 (0)