Skip to content

feat(compiler): add CustomScalarCoercer trait for custom scalar validation and coercion#1031

Open
Abdel-Monaam-Aouini wants to merge 5 commits intoapollographql:mainfrom
Abdel-Monaam-Aouini:add_CustomScalarCoercer
Open

feat(compiler): add CustomScalarCoercer trait for custom scalar validation and coercion#1031
Abdel-Monaam-Aouini wants to merge 5 commits intoapollographql:mainfrom
Abdel-Monaam-Aouini:add_CustomScalarCoercer

Conversation

@Abdel-Monaam-Aouini
Copy link
Copy Markdown
Contributor

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.

@Abdel-Monaam-Aouini Abdel-Monaam-Aouini requested a review from a team as a code owner March 31, 2026 08:30
/// 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>>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duckki check now :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants