mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-29 00:25:17 +03:00
27ce24b5fe
* Generalizes building a value from an AST, since "scalar" could be misleading, and supporting variable values within custom scalar literals can be valuable.
* Replaces isNullish with isInvalid since `null` is a meaningful value as a result of literal parsing.
* Provide reasonable default version of 'parseLiteral'
ref: 714ee980aa
ref: https://github.com/graphql/graphql-js/pull/903
# Conflicts:
# src/Utils/BuildSchema.php
# tests/Utils/BuildSchemaTest.php
116 lines
1.9 KiB
PHP
116 lines
1.9 KiB
PHP
<?php
|
|
namespace GraphQL\Tests\Executor;
|
|
|
|
use GraphQL\Type\Definition\ScalarType;
|
|
use GraphQL\Utils\Utils;
|
|
|
|
class Dog
|
|
{
|
|
function __construct($name, $woofs)
|
|
{
|
|
$this->name = $name;
|
|
$this->woofs = $woofs;
|
|
}
|
|
}
|
|
|
|
class Cat
|
|
{
|
|
function __construct($name, $meows)
|
|
{
|
|
$this->name = $name;
|
|
$this->meows = $meows;
|
|
}
|
|
}
|
|
|
|
class Human
|
|
{
|
|
function __construct($name)
|
|
{
|
|
$this->name = $name;
|
|
}
|
|
}
|
|
|
|
class Person
|
|
{
|
|
public $name;
|
|
public $pets;
|
|
public $friends;
|
|
|
|
function __construct($name, $pets = null, $friends = null)
|
|
{
|
|
$this->name = $name;
|
|
$this->pets = $pets;
|
|
$this->friends = $friends;
|
|
}
|
|
}
|
|
|
|
class ComplexScalar extends ScalarType
|
|
{
|
|
public static function create()
|
|
{
|
|
return new self();
|
|
}
|
|
|
|
public $name = 'ComplexScalar';
|
|
|
|
public function serialize($value)
|
|
{
|
|
if ($value === 'DeserializedValue') {
|
|
return 'SerializedValue';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function parseValue($value)
|
|
{
|
|
if ($value === 'SerializedValue') {
|
|
return 'DeserializedValue';
|
|
}
|
|
return Utils::undefined();
|
|
}
|
|
|
|
public function parseLiteral($valueNode, array $variables = null)
|
|
{
|
|
if ($valueNode->value === 'SerializedValue') {
|
|
return 'DeserializedValue';
|
|
}
|
|
return Utils::undefined();
|
|
}
|
|
}
|
|
|
|
class Special
|
|
{
|
|
public $value;
|
|
|
|
public function __construct($value)
|
|
{
|
|
$this->value = $value;
|
|
}
|
|
}
|
|
|
|
class NotSpecial
|
|
{
|
|
public $value;
|
|
|
|
public function __construct($value)
|
|
{
|
|
$this->value = $value;
|
|
}
|
|
}
|
|
|
|
class Adder
|
|
{
|
|
public $num;
|
|
|
|
public $test;
|
|
|
|
public function __construct($num)
|
|
{
|
|
$this->num = $num;
|
|
|
|
$this->test = function($source, $args, $context) {
|
|
return $this->num + $args['addend1'] + $context['addend2'];
|
|
};
|
|
}
|
|
}
|