feat(compiler): add CustomScalarCoercer trait for custom scalar validation and coercion#1031
Open
Abdel-Monaam-Aouini wants to merge 5 commits intoapollographql:mainfrom
Open
Conversation
…ation and coercion
duckki
reviewed
Apr 13, 2026
| /// Registered custom scalar coercers, keyed by scalar type name. | ||
| /// | ||
| /// Use [`Schema::add_custom_scalar_coercer`] to register a coercer. | ||
| custom_scalar_coercers: HashMap<Name, Arc<dyn CustomScalarCoercer>>, |
Contributor
There was a problem hiding this comment.
IMO, why don't we allow to set a blanket coercer that handles all customer scalars, instead of adding a map here. So, that the user can decide how to organize this -- either using a map or using a match statement, etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
Adds a CustomScalarCoercer trait that allows users to register custom
validation and coercion logic for custom scalar types. Previously, custom
scalars accepted any value without validation.
The trait provides two extension points:
coerce_variable_value: validates/transforms JSON variable values during input coercion
validate_ast_value: validates AST literal values (e.g., default values) during schema/document validation
Coercers are registered on the Schema via add_custom_scalar_coercer().
When no coercer is registered, the existing permissive behavior is preserved.