Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Provide better support for custom scalars #1160

Open
Kingdutch opened this issue Feb 4, 2021 · 0 comments
Open

[4.x] Provide better support for custom scalars #1160

Kingdutch opened this issue Feb 4, 2021 · 0 comments

Comments

@Kingdutch
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants