diff --git a/Resources/doc/definitions/custom-scalar.md b/Resources/doc/definitions/custom-scalar.md new file mode 100644 index 000000000..4bda799e0 --- /dev/null +++ b/Resources/doc/definitions/custom-scalar.md @@ -0,0 +1,53 @@ +# Custom scalar + +Here a simple example to add a custom scalar: + +```yaml +DateTime: + type: custom-scalar + config: + serialize: ["AppBundle\\DateTimeType", "serialize"] + parseValue: ["AppBundle\\DateTimeType", "parseValue"] + parseLiteral: ["AppBundle\\DateTimeType", "parseLiteral"] +``` + +```php +format('Y-m-d H:i:s'); + } + + /** + * @param mixed $value + * + * @return mixed + */ + public static function parseValue($value) + { + return new \DateTime($value); + } + + /** + * @param Node $valueNode + * + * @return string + */ + public static function parseLiteral($valueNode) + { + return new \DateTime($valueNode->value); + } +} +``` diff --git a/Resources/doc/definitions/index.md b/Resources/doc/definitions/index.md index 766f72cc6..c7c3e1b06 100644 --- a/Resources/doc/definitions/index.md +++ b/Resources/doc/definitions/index.md @@ -7,6 +7,7 @@ Definitions Go further ---------- +* [Custom scalar](custom-scalar.md) * [Mutation](mutation.md) * [Relay](relay/index.md) * [Builders](builders/index.md)