Skip to content

Commit

Permalink
Mutations Prototype (POC) #74
Browse files Browse the repository at this point in the history
- Added mutation support
- Added GraphQL functional test as an example of how to add mutations
  • Loading branch information
Alex Paliarush committed Jul 2, 2018
1 parent f947cad commit db3f2c7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/code/Magento/GraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
type Query {
}

type Mutation {
}

input FilterTypeInput @doc(description: "FilterTypeInput specifies which action will be performed in a query ") {
eq: String @doc(description: "Equals")
finset: [String] @doc(description: "Find in set. The value can contain a set of comma-separated values")
Expand All @@ -30,4 +33,4 @@ type SearchResultPageInfo @doc(description: "SearchResultPageInfo provides navig
enum SortEnum @doc(description: "This enumeration indicates whether to return results in ascending or descending order") {
ASC
DESC
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ type Query {
testItem(id: Int!) : Item @resolver(class: "Magento\\TestModuleGraphQlQuery\\Model\\Resolver\\Item")
}

type Mutation {
testItem(id: Int!) : MutationItem @resolver(class: "Magento\\TestModuleGraphQlQuery\\Model\\Resolver\\Item")
}

type Item {
item_id: Int
name: String
}

type MutationItem {
item_id: Int
name: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
type Item {
integer_list: [Int] @resolver(class: "Magento\\TestModuleGraphQlQueryExtension\\Model\\Resolver\\IntegerList")
}

type MutationItem {
integer_list: [Int] @resolver(class: "Magento\\TestModuleGraphQlQueryExtension\\Model\\Resolver\\IntegerList")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\GraphQl\TestModule;

use Magento\TestFramework\TestCase\GraphQlAbstract;

/**
* Make sure that it is possible to use GraphQL mutations in Magento
*/
class GraphQlMutationTest extends GraphQlAbstract
{
public function testMutation()
{
$id = 3;

$query = <<<MUTATION
mutation {
testItem(id: {$id}) {
item_id,
name,
integer_list
}
}
MUTATION;

$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('testItem', $response);
$testItem = $response['testItem'];
$this->assertArrayHasKey('integer_list', $testItem);
$this->assertEquals([4, 5, 6], $testItem['integer_list']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function generate() : Schema
$schema = $this->schemaFactory->create(
[
'query' => $this->outputMapper->getOutputType('Query'),
'mutation' => $this->outputMapper->getOutputType('Mutation'),
'typeLoader' => function ($name) {
return $this->outputMapper->getOutputType($name);
},
Expand Down

0 comments on commit db3f2c7

Please sign in to comment.