-
Notifications
You must be signed in to change notification settings - Fork 168
Allow using #[derive(GraphQLQuery)] without depending on serde
#487
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,8 @@ pub struct GraphQLClientCodegenOptions { | |
| fragments_other_variant: bool, | ||
| /// Skip Serialization of None values. | ||
| skip_serializing_none: bool, | ||
| /// Path to the serde crate. | ||
| serde_path: syn::Path, | ||
| } | ||
|
|
||
| impl GraphQLClientCodegenOptions { | ||
|
|
@@ -68,6 +70,7 @@ impl GraphQLClientCodegenOptions { | |
| extern_enums: Default::default(), | ||
| fragments_other_variant: Default::default(), | ||
| skip_serializing_none: Default::default(), | ||
| serde_path: syn::parse_quote!(::serde), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that the generated code is already dependent on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The It's been a while since I wrote the code here but I think that was the reason that I did it as an option here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You are right, this causes the least breaking change. The problem I see is that a config option is not good for discoverability. However, if you are using the codegen crate, then you are probably an advanced user. I think it makes sense to do it this way. |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -227,4 +230,14 @@ impl GraphQLClientCodegenOptions { | |
| pub fn skip_serializing_none(&self) -> &bool { | ||
| &self.skip_serializing_none | ||
| } | ||
|
|
||
| /// Set the path to used to resolve serde traits. | ||
| pub fn set_serde_path(&mut self, path: syn::Path) { | ||
| self.serde_path = path; | ||
| } | ||
|
|
||
| /// Get a reference to the path used to resolve serde traits. | ||
| pub fn serde_path(&self) -> &syn::Path { | ||
| &self.serde_path | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am conflicted on whether I like how this re-export works.
graphql_query_deriveas that crate defines the macro that uses it, or ingraphql_query_codegenas that crate produces the generated code?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A hidden module is a common pattern for private types used in macros (see serde, for an example). Adding a new public export is a bigger change than having it as a private module, regardless of whether publically exporting serde is an issue or not. I have not seen a crate publically re-export serde, though.
For the second point, this export needs to be in
graphql_client. That is the only crate that we know will be available to users of the library. Beyond that, you can't have non-proc-macro exports from a proc-macro crate which rules out exporting it fromgraphql_query_derive.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about that rule for proc-macro exports, then It makes total sense to do it in
graphql_client.