for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace DeInternetJongens\LighthouseUtils\Schema\Scalars;
use GraphQL\Error\Error;
use GraphQL\Language\AST\StringValueNode;
use GraphQL\Type\Definition\ScalarType;
class PostalCodeNl extends ScalarType
{
private const PATTERN = '/^\d{4}[a-zA-Z]{2}$/';
/** @var string */
public $name = 'PostalCodeNl';
public $description = 'A valid postalcode for The Netherlands with pattern [1234aa]. Example: 1234AA.';
/**
* @inheritDoc
*/
public function serialize($value)
return $value;
}
public function parseValue($value)
if (! \preg_match(self::PATTERN, $value)) {
throw new Error(sprintf('Input error: Expected valid postal code with pattern [1234aa], got: [%s]', $value));
public function parseLiteral($valueNode, array $variables = null)
if (! $valueNode instanceof StringValueNode) {
throw new Error('Query error: Can only parse strings got: ' . $valueNode->kind, [$valueNode]);
return $this->parseValue($valueNode->value);