GraphQL Create datetime type #2644

pull/2715/head
Angel Fernando Quiroz Campos 6 years ago
parent 1fde6cc054
commit 1b45923bf3
  1. 2
      src/ApiBundle/GraphQL/Resources/config/Query.types.yaml
  2. 6
      src/ApiBundle/GraphQL/Resources/config/Scalar.types.yaml
  3. 44
      src/ApiBundle/GraphQL/Type/DateTimeType.php

@ -61,7 +61,7 @@ UserMessage:
type: 'User'
resolve: "@=resolver('message_sender', [value])"
sendDate:
type: 'String'
type: 'DateTime'
excerpt:
type: 'String'
args:

@ -0,0 +1,6 @@
DateTime:
type: custom-scalar
config:
serialize: ["Chamilo\\ApiBundle\\GraphQL\\Type\\DateTimeType", "serialize"]
parseValue: ["Chamilo\\ApiBundle\\GraphQL\\Type\\DateTimeType", "parseValue"]
parseLiteral: ["Chamilo\\ApiBundle\\GraphQL\\Type\\DateTimeType", "parseLiteral"]

@ -0,0 +1,44 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\ApiBundle\GraphQL\Type;
use GraphQL\Language\AST\Node;
/**
* Class DateTimeType
*
* @package Chamilo\ApiBundle\GraphQL\Type
*/
class DateTimeType
{
/**
* @param \DateTime $value
*
* @return string
*/
public static function serialize(\DateTime $value)
{
return $value->format(\DateTime::ATOM);
}
/**
* @param string $value
*
* @return \DateTime
*/
public static function parseValue(string $value)
{
return new \DateTime($value, new \DateTimeZone('UTC'));
}
/**
* @param Node $valueNode
*
* @return \DateTime
*/
public static function parseLiteral(Node $valueNode)
{
return new \DateTime($valueNode->value, new \DateTimeZone('UTC'));
}
}
Loading…
Cancel
Save