Skip to content

Commit 973bded

Browse files
author
Jeremiah VALERIE
committed
Cover defaultValue
1 parent 902137e commit 973bded

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
imports:
2+
- { resource: ../config.yml }
3+
4+
overblog_graphql:
5+
definitions:
6+
config_validation: false
7+
class_namespace: "Overblog\\GraphQLBundle\\DefaultValue\\__DEFINITIONS__"
8+
schema:
9+
query: Mutation
10+
mutation: Mutation
11+
mappings:
12+
types:
13+
- type: yaml
14+
dir: "%kernel.project_dir%/config/defaultValue/mapping"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
Mutation:
3+
type: object
4+
config:
5+
fields:
6+
echo:
7+
type: String!
8+
resolve: "@=args['output']"
9+
args:
10+
output:
11+
type: String
12+
defaultValue: 'foo'
13+
isStringNull:
14+
type: Boolean!
15+
resolve: "@=null === args.getRawArguments()['string']"
16+
args:
17+
string:
18+
type: String
19+
defaultValue: null
20+
echoUsingInput:
21+
type: String!
22+
resolve: "@=args['input']['output']"
23+
args:
24+
input:
25+
type: EchoInput!
26+
isStringNullUsingInput:
27+
type: Boolean!
28+
resolve: "@=null === args.getRawArguments()['input']['string']"
29+
args:
30+
input:
31+
type: isStringNullInput!
32+
33+
echoUsingInputWithDefaultArg:
34+
type: String!
35+
resolve: "@=args['input']['output']"
36+
args:
37+
input:
38+
type: EchoInput
39+
defaultValue: {"output": "bar"}
40+
41+
EchoInput:
42+
type: input-object
43+
config:
44+
fields:
45+
output:
46+
type: String
47+
defaultValue: 'foo'
48+
49+
isStringNullInput:
50+
type: input-object
51+
config:
52+
fields:
53+
string:
54+
type: String
55+
defaultValue: null
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Overblog\GraphQLBundle\Tests\Functional\DisableBuiltInMapping;
4+
5+
use Overblog\GraphQLBundle\Tests\Functional\TestCase;
6+
7+
class DefaultValueTest extends TestCase
8+
{
9+
protected function setUp()
10+
{
11+
static::bootKernel(['test_case' => 'defaultValue']);
12+
}
13+
14+
public function testArgDefaultValue()
15+
{
16+
$query = 'mutation { echo }';
17+
18+
$result = $this->executeGraphQLRequest($query);
19+
20+
$this->assertTrue(empty($result['errors']));
21+
$this->assertSame('foo', $result['data']['echo']);
22+
}
23+
24+
public function testNullableDefaultValue()
25+
{
26+
$query = 'mutation { isStringNull }';
27+
28+
$result = $this->executeGraphQLRequest($query);
29+
30+
$this->assertTrue(empty($result['errors']));
31+
$this->assertTrue($result['data']['isStringNull']);
32+
}
33+
34+
public function testArgDefaultValueWithInput()
35+
{
36+
$query = 'mutation { echoUsingInput(input: {}) }';
37+
38+
$result = $this->executeGraphQLRequest($query);
39+
40+
$this->assertTrue(empty($result['errors']));
41+
$this->assertSame('foo', $result['data']['echoUsingInput']);
42+
}
43+
44+
public function testNullableDefaultValueWithInput()
45+
{
46+
$query = 'mutation { isStringNullUsingInput(input: {}) }';
47+
48+
$result = $this->executeGraphQLRequest($query);
49+
50+
$this->assertTrue(empty($result['errors']));
51+
$this->assertTrue($result['data']['isStringNullUsingInput']);
52+
}
53+
54+
public function testArgDefaultValueArgWithInput()
55+
{
56+
$query = 'mutation { echoUsingInputWithDefaultArg }';
57+
58+
$result = $this->executeGraphQLRequest($query);
59+
60+
$this->assertTrue(empty($result['errors']));
61+
$this->assertSame('bar', $result['data']['echoUsingInputWithDefaultArg']);
62+
}
63+
}

0 commit comments

Comments
 (0)