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

Refactor serde and ScalarValue relations #985

Merged
merged 5 commits into from
Oct 11, 2021

Conversation

tyranron
Copy link
Member

@tyranron tyranron commented Oct 11, 2021

Required for #975

Synopsis

This PR refactors the way serde is paired with ScalarValues. Previously, ScalarValue exposed Visitor associated type for InputValue<T> being able to delegate scalar value deserialization, #[derive(GraphQLScalarValue)] was always providing a Serializeimplementation. Such approach was causing issues for implementing ScalarValue for foreign types, because in most de::Visitor types are private and not exposed, which makes us to duplicate deserialization logic in our code, and user looses control over serialization.

Solution

The refactored approach requires only T: Deserialize for impl Deserialize for InputValue<T>, and, additionally, removes impl Serialize from the code generated by #[derive(GraphQLScalarValue)]. This allows:

  • to reuse any existing Deserialize impls for foreign types and require to do squats with exposing Visitor;
  • to give user full control over type serialization/deserialization.

Checklist

  • tests updated
  • documentation updated
  • changelog updated

@tyranron tyranron added enhancement Improvement of existing features or bugfix semver::breaking Breaking change in terms of SemVer labels Oct 11, 2021
@tyranron tyranron self-assigned this Oct 11, 2021
@tyranron tyranron merged commit f66296d into master Oct 11, 2021
@tyranron tyranron deleted the simplify-scalar-value-serde branch October 11, 2021 18:53
@tyranron tyranron added this to the 0.16.0 milestone Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix semver::breaking Breaking change in terms of SemVer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant