Skip to content

Commit ac61b3b

Browse files
committed
Merge branch 'bugfix/GQL-50' into develop
2 parents 2577b0c + a3b0193 commit ac61b3b

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

src/Mutation.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@ class Mutation extends Query
1515
* @var string
1616
*/
1717
protected const OPERATION_TYPE = 'mutation';
18+
19+
/**
20+
* @return string
21+
*/
22+
protected function constructSelectionSet(): string
23+
{
24+
if (empty($this->selectionSet)) return '';
25+
26+
return parent::constructSelectionSet();
27+
}
1828
}

src/Query.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace GraphQL;
44

5-
use Exception;
65
use GraphQL\Exception\ArgumentException;
76
use GraphQL\Exception\InvalidSelectionException;
87
use GraphQL\Exception\InvalidVariableException;
@@ -20,7 +19,7 @@ class Query
2019
*
2120
* @var string
2221
*/
23-
protected const QUERY_FORMAT = "%s%s {\n%s\n}";
22+
protected const QUERY_FORMAT = "%s%s%s";
2423

2524
/**
2625
* Stores the name of the type of the operation to be executed on the GraphQL server
@@ -34,42 +33,42 @@ class Query
3433
*
3534
* @var string
3635
*/
37-
private $operationName;
36+
protected $operationName;
3837

3938
/**
4039
* Stores the object being queried for
4140
*
4241
* @var string
4342
*/
44-
private $fieldName;
43+
protected $fieldName;
4544

4645
/**
4746
* Stores the list of variables to be used in the query
4847
*
4948
* @var array|Variable[]
5049
*/
51-
private $variables;
50+
protected $variables;
5251

5352
/**
5453
* Stores the list of arguments used when querying data
5554
*
5655
* @var array
5756
*/
58-
private $arguments;
57+
protected $arguments;
5958

6059
/**
6160
* Stores the selection set desired to get from the query, can include nested queries
6261
*
6362
* @var array
6463
*/
65-
private $selectionSet;
64+
protected $selectionSet;
6665

6766
/**
6867
* Private member that's not accessible from outside the class, used internally to deduce if query is nested or not
6968
*
7069
* @var bool
7170
*/
72-
private $isNested;
71+
protected $isNested;
7372

7473
/**
7574
* GQLQueryBuilder constructor.
@@ -238,7 +237,7 @@ protected function constructArguments(): string
238237
*/
239238
protected function constructSelectionSet(): string
240239
{
241-
$attributesString = '';
240+
$attributesString = " {\n";
242241
$first = true;
243242
foreach ($this->selectionSet as $attribute) {
244243

@@ -257,6 +256,7 @@ protected function constructSelectionSet(): string
257256
// Append attribute to returned attributes list
258257
$attributesString .= $attribute;
259258
}
259+
$attributesString .= "\n}";
260260

261261
return $attributesString;
262262
}

src/QueryBuilder/QueryBuilder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace GraphQL\QueryBuilder;
44

55
use GraphQL\Query;
6-
use GraphQL\Variable;
76

87
/**
98
* Class QueryBuilder

tests/MutationTest.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,39 @@ public function testMutationWithoutOperationType()
1616

1717
$this->assertEquals(
1818
'mutation {
19-
createObject {
20-
21-
}
19+
createObject
2220
}',
2321
(string) $mutation
2422
);
2523
}
2624

25+
// /**
26+
// *
27+
// */
28+
// public function testMutationWithOperationType()
29+
// {
30+
// $mutation = new Mutation('mutation');
31+
//
32+
// $this->assertEquals(
33+
// 'mutation {
34+
//
35+
//}',
36+
// (string) $mutation
37+
// );
38+
// }
39+
2740
/**
2841
*
2942
*/
30-
public function testMutationWithOperationType()
43+
public function testMutationWithoutSelectedFields()
3144
{
32-
$mutation = new Mutation('mutation');
33-
45+
$mutation = (new Mutation('createObject'))
46+
->setArguments(['name' => 'TestObject', 'type' => 'TestType']);
3447
$this->assertEquals(
3548
'mutation {
36-
49+
createObject(name: "TestObject" type: "TestType")
3750
}',
38-
(string) $mutation
39-
);
51+
(string) $mutation);
4052
}
4153

4254
/**

0 commit comments

Comments
 (0)