From a14fd0f09e1d322283cd946b62323575076e4ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Nerma?= Date: Mon, 24 Oct 2022 12:26:40 +0200 Subject: [PATCH 1/2] Add support for 'input_name_suffix_ in '#[graphql(...)]' (fixes #1117) --- CHANGELOG.md | 4 ++++ derive/src/args.rs | 8 ++++++++ derive/src/input_object.rs | 6 +++++- derive/src/oneof_object.rs | 7 ++++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2507c71af..939db085c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/derive/src/args.rs b/derive/src/args.rs index 28efac22d..51335278f 100644 --- a/derive/src/args.rs +++ b/derive/src/args.rs @@ -223,6 +223,8 @@ pub struct SimpleObject { #[darling(default)] pub input_name: Option, #[darling(default)] + pub input_name_suffix: Option, + #[darling(default)] pub guard: Option>, } @@ -393,6 +395,8 @@ pub struct Union { // for OneofObject #[darling(default)] pub input_name: Option, + #[darling(default)] + pub input_name_suffix: Option, } #[derive(FromVariant)] @@ -459,6 +463,8 @@ pub struct InputObject { #[darling(default)] pub input_name: Option, #[darling(default)] + pub input_name_suffix: Option, + #[darling(default)] pub rename_fields: Option, #[darling(default)] pub visible: Option, @@ -511,6 +517,8 @@ pub struct OneofObject { #[darling(default)] pub input_name: Option, #[darling(default)] + pub input_name_suffix: Option, + #[darling(default)] pub name_type: bool, #[darling(default)] pub rename_fields: Option, diff --git a/derive/src/input_object.rs b/derive/src/input_object.rs index 56cdecbb8..5aad0c2f0 100644 --- a/derive/src/input_object.rs +++ b/derive/src/input_object.rs @@ -47,12 +47,16 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult } 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!(::type_name()) diff --git a/derive/src/oneof_object.rs b/derive/src/oneof_object.rs index 9b2fd6fe6..0f04bb339 100644 --- a/derive/src/oneof_object.rs +++ b/derive/src/oneof_object.rs @@ -23,11 +23,16 @@ pub fn generate(object_args: &args::OneofObject) -> GeneratorResult .map(|tag| quote!(::std::string::ToString::to_string(#tag))) .collect::>(); 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!(::type_name()) From fd20c63308b24330c995be1c15a5f5f71b9117cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Nerma?= Date: Thu, 2 Mar 2023 21:38:18 +0100 Subject: [PATCH 2/2] Bump version number --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0064cf296..790652376 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ license = "MIT/Apache-2.0" name = "async-graphql" readme = "README.md" repository = "https://github.com/async-graphql/async-graphql" -version = "5.0.6" +version = "5.0.7" [features] apollo_persisted_queries = ["lru", "sha2"]