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

Implement ScalarValue derive macro #1025

Merged
merged 104 commits into from
Mar 3, 2022
Merged

Implement ScalarValue derive macro #1025

merged 104 commits into from
Mar 3, 2022

Conversation

ilslv
Copy link
Member

@ilslv ilslv commented Feb 15, 2022

Synopsis

After redesign GraphQLScalar value lost ability to derive ScalarValue on enums.

Solution

Implement GraphQLScalarValue derive macro to implement ScalarValue on enums.

Checklist

  • Created PR:
    • In draft mode
    • Name contains Draft: prefix
    • Name contains issue reference
    • Has assignee
  • Documentation is updated (if required)
  • Tests are updated (if required)
  • Changes conform code style
  • CHANGELOG entry is added (if required)
  • FCM (final commit message) is posted
    • and approved
  • Review is completed and changes are approved
  • Before merge:
    • Milestone is set
    • PR's name and description are correct and up-to-date
    • Draft: prefix is removed
    • All temporary labels are removed

@ilslv ilslv added enhancement Improvement of existing features or bugfix k::api Related to API (application interface) labels Feb 15, 2022
@ilslv ilslv self-assigned this Feb 15, 2022
@ilslv
Copy link
Member Author

ilslv commented Feb 15, 2022

FCM

Redesign `#[derive(ScalarValue)]` macro to derive `ScalarValue` on enums (#1025)

@ilslv ilslv marked this pull request as ready for review February 15, 2022 08:07
# Conflicts:
#	integration_tests/juniper_tests/src/codegen/mod.rs
#	juniper/CHANGELOG.md
#	juniper_codegen/src/lib.rs
# Conflicts:
#	integration_tests/juniper_tests/src/codegen/mod.rs
#	integration_tests/juniper_tests/src/codegen/scalar_attr_derive_input.rs
#	integration_tests/juniper_tests/src/codegen/scalar_attr_type_alias.rs
#	integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs
#	integration_tests/juniper_tests/src/custom_scalar.rs
#	juniper/CHANGELOG.md
#	juniper/src/lib.rs
#	juniper/src/types/scalars.rs
#	juniper/src/value/scalar.rs
#	juniper_codegen/src/derive_scalar_value.rs
#	juniper_codegen/src/graphql_scalar/attr.rs
#	juniper_codegen/src/graphql_scalar/derive.rs
#	juniper_codegen/src/graphql_scalar/mod.rs
#	juniper_codegen/src/lib.rs
#	juniper_codegen/src/result.rs
@ilslv ilslv requested a review from tyranron March 1, 2022 09:37
Copy link
Member

@tyranron tyranron left a comment

Choose a reason for hiding this comment

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

@ilslv let's reshape it a little bit more.

@@ -549,6 +550,114 @@ pub fn graphql_scalar(attr: TokenStream, body: TokenStream) -> TokenStream {
.into()
}

/// `#[derive(GraphQLScalarValue)]` macro for deriving a [`ScalarValue`]
Copy link
Member

Choose a reason for hiding this comment

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

Then let's name it #[derive(ScalarValue)] directly. There is no sense stopping us from that.

Copy link
Member Author

Choose a reason for hiding this comment

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

@tyranron should we also rename attributes from #[graphql(...)] to #[scalar_value(...)]?

Copy link
Member

Choose a reason for hiding this comment

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

@ilslv I think #[value(...)] will be just OK.

///
/// To derive [`ScalarValue`] on enum you should mark corresponding enum
/// variants with `as_int`/`as_float`/`as_string`/`into_string`/`as_str`/
/// `as_boolean` attributes (names correspond to [`ScalarValue`] required
Copy link
Member

Choose a reason for hiding this comment

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

Let's rename as_bool directly in the trait, so it complies with Rust types naming. And remove as_boolean variant totally.

@ilslv ilslv changed the title Implement GraphQLScalarValue derive macro Implement ScalarValue derive macro Mar 2, 2022
@ilslv ilslv requested a review from tyranron March 2, 2022 10:35
@tyranron tyranron merged commit 5bbc73a into master Mar 3, 2022
@tyranron tyranron deleted the derive-scalar-value branch March 3, 2022 13:49
@tyranron tyranron added this to the 0.16.0 milestone Apr 13, 2022
@tyranron tyranron mentioned this pull request Jun 1, 2022
5 tasks
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 k::api Related to API (application interface)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants