Description
Custom scalars are a great way to give standard types more meaning and to aid in input validation (e.g. for emails, URLs or timestamps).
A good place to inject these custom scalar types would be in SdlSchemaPluginBase::getSchema
which has the following snippet.
$schema = BuildSchema::build($document, function ($config, TypeDefinitionNode $type) use ($resolver) {
if ($type instanceof InterfaceTypeDefinitionNode || $type instanceof UnionTypeDefinitionNode) {
$config['resolveType'] = $resolver;
}
return $config;
});
The provided definition extender will also be called for custom scalar types. This allows to adjust the $config
array passed to the CustomScalarConfig
class in ASTDefinitionBuilder::makeSchemaDefFromConfig
. However, this requires overwriting the getSchema
function in the SdlSchemaPluginBase
class and will require you to specify separate functions in an array.
A more ergonomic way would be to introduce/expose the type registry for the GraphQL module that allows registering custom classes for custom scalars.
I'm not sure if the ResolverRegistry
would be the best place to accommodate this? It's not really a resolver but more a serializer/deserializer per scalar type.