Skip to content

Commit

Permalink
Add support for 'input_name_suffix_ in '#[graphql(...)]' (fixes async…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNerma committed Mar 2, 2023
1 parent 94a3310 commit a14fd0f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [5.0.7] 2023-03-02

- Add support for `input_name_suffix` in `#[graphql(...)]` attribute [#1117](https://github.com/async-graphql/async-graphql/issues/1117)

# [5.0.6] 2023-02-11

- docs: Tweak dataloader example and link to full example [#1194](https://github.com/async-graphql/async-graphql/pull/1194)
Expand Down
8 changes: 8 additions & 0 deletions derive/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ pub struct SimpleObject {
#[darling(default)]
pub input_name: Option<String>,
#[darling(default)]
pub input_name_suffix: Option<String>,
#[darling(default)]
pub guard: Option<SpannedValue<String>>,
}

Expand Down Expand Up @@ -393,6 +395,8 @@ pub struct Union {
// for OneofObject
#[darling(default)]
pub input_name: Option<String>,
#[darling(default)]
pub input_name_suffix: Option<String>,
}

#[derive(FromVariant)]
Expand Down Expand Up @@ -459,6 +463,8 @@ pub struct InputObject {
#[darling(default)]
pub input_name: Option<String>,
#[darling(default)]
pub input_name_suffix: Option<String>,
#[darling(default)]
pub rename_fields: Option<RenameRule>,
#[darling(default)]
pub visible: Option<Visible>,
Expand Down Expand Up @@ -511,6 +517,8 @@ pub struct OneofObject {
#[darling(default)]
pub input_name: Option<String>,
#[darling(default)]
pub input_name_suffix: Option<String>,
#[darling(default)]
pub name_type: bool,
#[darling(default)]
pub rename_fields: Option<RenameRule>,
Expand Down
6 changes: 5 additions & 1 deletion derive/src/input_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
}

let gql_typename = if !object_args.name_type {
let name = object_args
let mut name = object_args
.input_name
.clone()
.or_else(|| object_args.name.clone())
.unwrap_or_else(|| RenameTarget::Type.rename(ident.to_string()));

if let Some(suffix) = &object_args.input_name_suffix {
name.push_str(suffix);
}

quote!(::std::borrow::Cow::Borrowed(#name))
} else {
quote!(<Self as #crate_name::TypeName>::type_name())
Expand Down
7 changes: 6 additions & 1 deletion derive/src/oneof_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ pub fn generate(object_args: &args::OneofObject) -> GeneratorResult<TokenStream>
.map(|tag| quote!(::std::string::ToString::to_string(#tag)))
.collect::<Vec<_>>();
let gql_typename = if !object_args.name_type {
let name = object_args
let mut name = object_args
.input_name
.clone()
.or_else(|| object_args.name.clone())
.unwrap_or_else(|| RenameTarget::Type.rename(ident.to_string()));

if let Some(suffix) = &object_args.input_name_suffix {
name.push_str(suffix);
}

quote!(::std::borrow::Cow::Borrowed(#name))
} else {
quote!(<Self as #crate_name::TypeName>::type_name())
Expand Down

0 comments on commit a14fd0f

Please sign in to comment.