-
Hello! |
Beta Was this translation helpful? Give feedback.
Answered by
Vincz
Sep 23, 2021
Replies: 1 comment
-
Hi. It's quite easy to make your own. <?php
declare(strict_types=1);
namespace App\GraphQL\Scalar;
use GraphQL\Language\AST\BooleanValueNode;
use GraphQL\Language\AST\FloatValueNode;
use GraphQL\Language\AST\IntValueNode;
use GraphQL\Language\AST\ListValueNode;
use GraphQL\Language\AST\ObjectValueNode;
use GraphQL\Language\AST\StringValueNode;
use Overblog\GraphQLBundle\Annotation as GQL;
#[GQL\Scalar]
#[GQL\Description('Json scalar type')]
class Json
{
public static function serialize($value)
{
return $value;
}
public static function parseValue($value)
{
return $value;
}
public static function parseLiteral($valueNode)
{
switch ($valueNode) {
case $valueNode instanceof StringValueNode:
case $valueNode instanceof BooleanValueNode:
return $valueNode->value;
case $valueNode instanceof IntValueNode:
case $valueNode instanceof FloatValueNode:
return \floatval($valueNode->value);
case $valueNode instanceof ObjectValueNode:
$value = [];
foreach ($valueNode->fields as $field) {
$value[$field->name->value] = self::parseLiteral($field->value);
}
return $value;
case $valueNode instanceof ListValueNode:
return \array_map([self, 'parseLiteral'], $valueNode->values);
default:
return null;
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
scion4581
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Hi. It's quite easy to make your own.
Here is an example with attributes: