Skip to content

Commit

Permalink
ENGCOM-2278: Mutations Prototype (POC) #74 #114
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Idolov authored Jul 11, 2018
2 parents 53241b9 + a7b12cb commit 59431c0
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
6 changes: 5 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,10 @@
type Query {
}

type Mutation {
placeholderMutation: String @doc(description: "Mutation type cannot be declared without fields. The placeholder will be removed when at least one mutation field is declared.")
}

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 +34,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 @@ -2,6 +2,10 @@ type Query {
placeholder: String @doc(description: "comment for placeholder.")
}

type Mutation {
placeholder: String @doc(description: "comment for placeholder.")
}

input FilterTypeInput @doc(description:"Comment for FilterTypeInput") {
eq: String @doc(description:"Equal")
finset: [String]
Expand Down
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 59431c0

Please sign in to comment.