Skip to content

Commit db3f2c7

Browse files
author
Alex Paliarush
committed
Mutations Prototype (POC) #74
- Added mutation support - Added GraphQL functional test as an example of how to add mutations
1 parent f947cad commit db3f2c7

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

app/code/Magento/GraphQl/etc/schema.graphqls

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
type Query {
55
}
66

7+
type Mutation {
8+
}
9+
710
input FilterTypeInput @doc(description: "FilterTypeInput specifies which action will be performed in a query ") {
811
eq: String @doc(description: "Equals")
912
finset: [String] @doc(description: "Find in set. The value can contain a set of comma-separated values")
@@ -30,4 +33,4 @@ type SearchResultPageInfo @doc(description: "SearchResultPageInfo provides navig
3033
enum SortEnum @doc(description: "This enumeration indicates whether to return results in ascending or descending order") {
3134
ASC
3235
DESC
33-
}
36+
}

dev/tests/api-functional/_files/Magento/TestModuleGraphQlQuery/etc/schema.graphqls

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ type Query {
55
testItem(id: Int!) : Item @resolver(class: "Magento\\TestModuleGraphQlQuery\\Model\\Resolver\\Item")
66
}
77

8+
type Mutation {
9+
testItem(id: Int!) : MutationItem @resolver(class: "Magento\\TestModuleGraphQlQuery\\Model\\Resolver\\Item")
10+
}
11+
812
type Item {
913
item_id: Int
1014
name: String
1115
}
16+
17+
type MutationItem {
18+
item_id: Int
19+
name: String
20+
}

dev/tests/api-functional/_files/Magento/TestModuleGraphQlQueryExtension/etc/schema.graphqls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
type Item {
55
integer_list: [Int] @resolver(class: "Magento\\TestModuleGraphQlQueryExtension\\Model\\Resolver\\IntegerList")
66
}
7+
8+
type MutationItem {
9+
integer_list: [Int] @resolver(class: "Magento\\TestModuleGraphQlQueryExtension\\Model\\Resolver\\IntegerList")
10+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\TestModule;
9+
10+
use Magento\TestFramework\TestCase\GraphQlAbstract;
11+
12+
/**
13+
* Make sure that it is possible to use GraphQL mutations in Magento
14+
*/
15+
class GraphQlMutationTest extends GraphQlAbstract
16+
{
17+
public function testMutation()
18+
{
19+
$id = 3;
20+
21+
$query = <<<MUTATION
22+
mutation {
23+
testItem(id: {$id}) {
24+
item_id,
25+
name,
26+
integer_list
27+
}
28+
}
29+
MUTATION;
30+
31+
$response = $this->graphQlQuery($query);
32+
$this->assertArrayHasKey('testItem', $response);
33+
$testItem = $response['testItem'];
34+
$this->assertArrayHasKey('integer_list', $testItem);
35+
$this->assertEquals([4, 5, 6], $testItem['integer_list']);
36+
}
37+
}

lib/internal/Magento/Framework/GraphQl/Schema/SchemaGenerator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function generate() : Schema
5656
$schema = $this->schemaFactory->create(
5757
[
5858
'query' => $this->outputMapper->getOutputType('Query'),
59+
'mutation' => $this->outputMapper->getOutputType('Mutation'),
5960
'typeLoader' => function ($name) {
6061
return $this->outputMapper->getOutputType($name);
6162
},

0 commit comments

Comments
 (0)