-
Notifications
You must be signed in to change notification settings - Fork 433
Implement newtype derive for scalars. #368
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
Implement newtype derive for scalars. #368
Conversation
c4d8890
to
3d159f3
Compare
Codecov Report
@@ Coverage Diff @@
## master #368 +/- ##
==========================================
- Coverage 86.08% 85.72% -0.37%
==========================================
Files 107 108 +1
Lines 15600 15710 +110
==========================================
+ Hits 13429 13467 +38
- Misses 2171 2243 +72
Continue to review full report at Codecov.
|
@LegNeato ping |
I haven't looked at this super closely, but why would you ever not want Can we do it automatically for newtypes like serde does? |
Serde requires the Technically we could just do newtype for tuple structs with a single filed, but since we are reusing the macro for two different purposes I prefer to be explicit. It also gives some more clarity as to what's happening for the reader of the code, and it's analogous to serde and |
But what about this from https://serde.rs/impl-serialize.html:
And this link shows that the |
I always thought the #transparent attr was mandatory. Not so sure if we'd want to support that. |
I think we should mirror serde's behavior whenever possible...it's very ergonomic and battle-tested. |
Any update on this? I need it for a project so happy to do the final tweaks if you don't have time. |
I removed the requirement for the I would'nt support anything other than single field tuple structs for now though. Better to be conservative and reconsider once someone asks for it. So should be good to merge. |
Just to nitpick - should we take out |
This commit implements a newtype style custom derive for scalars via `#[derive(GraphQLScalarValue)]`, which now supports both deriving a base enum scalar type and newtypes. For newtypes, the `#[graphql(transparent)]` attribute is required. This commit: * implements the derive * adds integration tests * updates the book
6ca3806
to
0268d03
Compare
This commit implements a newtype style custom derive
for scalars via
#[derive(GraphQLScalarValue)]
, which nowsupports both deriving a base enum scalar type and newtypes.
For newtypes, the
#[graphql(transparent)]
attribute isrequired.
This commit:
Closes #303