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

feat: custom ser/de for scalars #980

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Conversation

obmarg
Copy link
Owner

@obmarg obmarg commented Jun 9, 2024

Why are we making this change?

One of cynics features is that it allows you to use types from any crate as custom scalars, bypassing the usual orphan rule restrictions. In other words, cynic doesn't have to specifically add support for that crate, and that crate doesn't need to add support for cynic either.

Currently this uses the serde::Serialize & serde::Deserialize impls for the type. This is fine when the format used by the serde impls matches that used by the server you're talking to. But when the format does not match, you can no longer use the type directly, and have to create a wrapping newtype instead.

What effects does this change have?

This PR updates the cynic code so that it uses a set of cynic traits for serialising & deserialising scalars. These types are generic over the underlying schema type - allowing the ser/de of scalars to hook into the same schema specific mechanisms we do to match types to custom scalars.

This means that an application can serialise one individual type differently depending on what the server it's sending to expects.

Fixes #782

Todo:

  • There's at least one todo!() in there.
  • There's some commented out code that needs fixed
  • More thorough tests of flatten to make sure I've not broken it
  • Doc updates
  • Write tests of this functionality.
  • Figure out if I need more where bounds on some of the generated impls

@obmarg obmarg added this to the 4.0.0 milestone Jun 9, 2024
@obmarg obmarg added the breaking A breaking change label Jun 9, 2024
Copy link

netlify bot commented Jun 9, 2024

Deploy Preview for cynic-querygen-web ready!

Name Link
🔨 Latest commit 98146da
🔍 Latest deploy log https://app.netlify.com/sites/cynic-querygen-web/deploys/6665c612f186880008421f32
😎 Deploy Preview https://deploy-preview-980--cynic-querygen-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

Successfully merging this pull request may close these issues.

Custom (de)serializers
1 participant