-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
277 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
namespace Youshido\Tests\Issues\Issue90; | ||
|
||
use Youshido\GraphQL\Config\Schema\SchemaConfig; | ||
use Youshido\GraphQL\Schema\AbstractSchema; | ||
use Youshido\GraphQL\Type\Object\ObjectType; | ||
use Youshido\GraphQL\Type\Scalar\DateTimeType; | ||
|
||
class Issue90Schema extends AbstractSchema | ||
{ | ||
|
||
public function build(SchemaConfig $config) | ||
{ | ||
$config->setQuery( | ||
new ObjectType([ | ||
'name' => 'QueryType', | ||
'fields' => [ | ||
'echo' => [ | ||
'type' => new DateTimeType('Y-m-d H:ia'), | ||
'args' => [ | ||
'date' => new DateTimeType('Y-m-d H:ia') | ||
], | ||
'resolve' => function ($value, $args, $info) { | ||
|
||
if (isset($args['date'])) { | ||
return $args['date']; | ||
} | ||
|
||
return null; | ||
} | ||
] | ||
] | ||
]) | ||
); | ||
|
||
$config->setMutation( | ||
new ObjectType([ | ||
'name' => 'MutationType', | ||
'fields' => [ | ||
'echo' => [ | ||
'type' => new DateTimeType('Y-m-d H:ia'), | ||
'args' => [ | ||
'date' => new DateTimeType('Y-m-d H:ia') | ||
], | ||
'resolve' => function ($value, $args, $info) { | ||
|
||
if (isset($args['date'])) { | ||
return $args['date']; | ||
} | ||
|
||
return null; | ||
} | ||
] | ||
] | ||
]) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Youshido\Tests\Issues\Issue90; | ||
|
||
use Youshido\GraphQL\Execution\Processor; | ||
use Youshido\Tests\Issues\Issue90\Issue90Schema; | ||
|
||
/** | ||
* User: stefano.corallo | ||
* Date: 25/11/16 | ||
* Time: 9.39 | ||
*/ | ||
class Issue90Test extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
public function testQueryDateTimeTypeWithDateParameter() | ||
{ | ||
$schema = new Issue90Schema(); | ||
$processor = new Processor($schema); | ||
$processor->processPayload("query{ echo(date: \"2016-11-25 09:53am\") }"); | ||
$res = $processor->getResponseData(); | ||
|
||
self::assertCount(1, $res, "Invalid response array received"); //only data expected | ||
|
||
self::assertNotNull($res['data']['echo'], "Invalid echo response received"); | ||
|
||
self::assertEquals("2016-11-25 09:53am", $res['data']['echo']); | ||
} | ||
|
||
public function testQueryDateTimeTypeWithoutParameter() | ||
{ | ||
$processor = new Processor(new Issue90Schema()); | ||
$processor->processPayload("query{ echo }"); | ||
$res = $processor->getResponseData(); | ||
|
||
self::assertCount(1, $res, "Invalid response array received"); //only data expected | ||
|
||
self::assertNull($res['data']['echo']); | ||
} | ||
|
||
public function testQueryDateTimeTypeWithNullParameter() | ||
{ | ||
$processor = new Processor(new Issue90Schema()); | ||
$processor->processPayload("query{ echo(date: null) }"); | ||
$res = $processor->getResponseData(); | ||
|
||
self::assertCount(1, $res, "Invalid response array received"); //only data expected | ||
|
||
self::assertNull($res['data']['echo'], "Error Quering with explicit date null parameter "); | ||
} | ||
|
||
public function testMutatingDateTimeWithParameter() | ||
{ | ||
$schema = new Issue90Schema(); | ||
$processor = new Processor($schema); | ||
$processor->processPayload("mutation{ echo(date: \"2016-11-25 09:53am\") }"); | ||
$res = $processor->getResponseData(); | ||
|
||
self::assertCount(1, $res, "Invalid response array received"); //only data expected | ||
|
||
self::assertNotNull($res['data']['echo'], "Invalid echo response received during mutation of date parameter"); | ||
|
||
self::assertEquals("2016-11-25 09:53am", $res['data']['echo']); | ||
} | ||
|
||
public function testMutatingDateTimeWithExplicitNullParameter() | ||
{ | ||
$schema = new Issue90Schema(); | ||
$processor = new Processor($schema); | ||
$processor->processPayload("mutation{ echo(date: null) }"); | ||
$res = $processor->getResponseData(); | ||
|
||
self::assertCount(1, $res, "Invalid response array received"); //only data expected | ||
self::assertNull($res['data']['echo'], "Invalid echo response received during mutation of date parameter with explicit null value"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.