Skip to content

Commit 3d373bd

Browse files
committed
Add the custom scalar option as derive attribute
1 parent acfe3be commit 3d373bd

File tree

1 file changed

+13
-0
lines changed
  • graphql_query_derive/src

1 file changed

+13
-0
lines changed

graphql_query_derive/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ fn build_graphql_client_derive_options(
7070
) -> Result<GraphQLClientCodegenOptions, BoxError> {
7171
let variables_derives = attributes::extract_attr(input, "variables_derives").ok();
7272
let response_derives = attributes::extract_attr(input, "response_derives").ok();
73+
let custom_scalars_module = attributes::extract_attr(input, "custom_scalars_module").ok();
7374

7475
let mut options = GraphQLClientCodegenOptions::new(CodegenMode::Derive);
7576
options.set_query_file(query_path);
@@ -92,6 +93,18 @@ fn build_graphql_client_derive_options(
9293
options.set_normalization(normalization);
9394
};
9495

96+
// The user can give a path to a module that provides definitions for the custom scalars.
97+
if let Some(custom_scalars_module) = custom_scalars_module {
98+
let custom_scalars_module = syn::parse_str(&custom_scalars_module).map_err(|err| {
99+
GeneralError(format!(
100+
"Invalid custom scalars module path: {}. {}",
101+
custom_scalars_module, err
102+
))
103+
})?;
104+
105+
options.set_custom_scalars_module(custom_scalars_module);
106+
}
107+
95108
options.set_struct_ident(input.ident.clone());
96109
options.set_module_visibility(input.vis.clone());
97110
options.set_operation_name(input.ident.to_string());

0 commit comments

Comments
 (0)