Skip to content

Commit

Permalink
Cover defaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web committed May 4, 2021
1 parent 902137e commit 973bded
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/Functional/App/config/defaultValue/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
imports:
- { resource: ../config.yml }

overblog_graphql:
definitions:
config_validation: false
class_namespace: "Overblog\\GraphQLBundle\\DefaultValue\\__DEFINITIONS__"
schema:
query: Mutation
mutation: Mutation
mappings:
types:
- type: yaml
dir: "%kernel.project_dir%/config/defaultValue/mapping"
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

Mutation:
type: object
config:
fields:
echo:
type: String!
resolve: "@=args['output']"
args:
output:
type: String
defaultValue: 'foo'
isStringNull:
type: Boolean!
resolve: "@=null === args.getRawArguments()['string']"
args:
string:
type: String
defaultValue: null
echoUsingInput:
type: String!
resolve: "@=args['input']['output']"
args:
input:
type: EchoInput!
isStringNullUsingInput:
type: Boolean!
resolve: "@=null === args.getRawArguments()['input']['string']"
args:
input:
type: isStringNullInput!

echoUsingInputWithDefaultArg:
type: String!
resolve: "@=args['input']['output']"
args:
input:
type: EchoInput
defaultValue: {"output": "bar"}

EchoInput:
type: input-object
config:
fields:
output:
type: String
defaultValue: 'foo'

isStringNullInput:
type: input-object
config:
fields:
string:
type: String
defaultValue: null
63 changes: 63 additions & 0 deletions tests/Functional/DefaultValue/DefaultValueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Overblog\GraphQLBundle\Tests\Functional\DisableBuiltInMapping;

use Overblog\GraphQLBundle\Tests\Functional\TestCase;

class DefaultValueTest extends TestCase
{
protected function setUp()
{
static::bootKernel(['test_case' => 'defaultValue']);
}

public function testArgDefaultValue()
{
$query = 'mutation { echo }';

$result = $this->executeGraphQLRequest($query);

$this->assertTrue(empty($result['errors']));
$this->assertSame('foo', $result['data']['echo']);
}

public function testNullableDefaultValue()
{
$query = 'mutation { isStringNull }';

$result = $this->executeGraphQLRequest($query);

$this->assertTrue(empty($result['errors']));
$this->assertTrue($result['data']['isStringNull']);
}

public function testArgDefaultValueWithInput()
{
$query = 'mutation { echoUsingInput(input: {}) }';

$result = $this->executeGraphQLRequest($query);

$this->assertTrue(empty($result['errors']));
$this->assertSame('foo', $result['data']['echoUsingInput']);
}

public function testNullableDefaultValueWithInput()
{
$query = 'mutation { isStringNullUsingInput(input: {}) }';

$result = $this->executeGraphQLRequest($query);

$this->assertTrue(empty($result['errors']));
$this->assertTrue($result['data']['isStringNullUsingInput']);
}

public function testArgDefaultValueArgWithInput()
{
$query = 'mutation { echoUsingInputWithDefaultArg }';

$result = $this->executeGraphQLRequest($query);

$this->assertTrue(empty($result['errors']));
$this->assertSame('bar', $result['data']['echoUsingInputWithDefaultArg']);
}
}

0 comments on commit 973bded

Please sign in to comment.