From 8be451b5bdb8ae5f1cbb0f3f8a5708ded1022ffd Mon Sep 17 00:00:00 2001 From: Sunli <20092316+sunli829@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:34:57 +0800 Subject: [PATCH] Fix impossible to specify both `name` and `input_name`. #987 --- CHANGELOG.md | 9 +++++++++ derive/src/input_object.rs | 4 ++-- tests/input_object.rs | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fba2d667..6ee1f5e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ 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). +# [4.0.5] 2022-07-18 + +- Fix serializing of JSON default values [#969](https://github.com/async-graphql/async-graphql/issues/969) +- Bump `rocket-0.5.0-rc.1` to `rocket-0.5.0-rc.2` for `async-graphql-rocket` [#968](https://github.com/async-graphql/async-graphql/pull/968) +- Implement `Default` for `StringNumber` [#980](https://github.com/async-graphql/async-graphql/issues/980) +- Implement `Guard` for `Fn` +- Fix impossible to specify both `name` and `input_name` [#987](https://github.com/async-graphql/async-graphql/issues/987) + + # [4.0.4] 2022-6-25 - Bump Actix-web from `4.0.1` to `4.1.0` diff --git a/derive/src/input_object.rs b/derive/src/input_object.rs index 7ca49f15..e33a9408 100644 --- a/derive/src/input_object.rs +++ b/derive/src/input_object.rs @@ -41,9 +41,9 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult } let gql_typename = object_args - .name + .input_name .clone() - .or_else(|| object_args.input_name.clone()) + .or_else(|| object_args.name.clone()) .unwrap_or_else(|| RenameTarget::Type.rename(ident.to_string())); let desc = get_rustdoc(&object_args.attrs)? diff --git a/tests/input_object.rs b/tests/input_object.rs index 345a3fec..bcd8dd91 100644 --- a/tests/input_object.rs +++ b/tests/input_object.rs @@ -407,6 +407,23 @@ pub async fn test_both_input_output() { assert_eq!(::type_name(), "MyObject"); } +#[tokio::test] +pub async fn test_both_input_output_2() { + #[derive(SimpleObject, InputObject)] + #[graphql(name = "MyObj", input_name = "MyObjectInput")] + #[allow(dead_code)] + struct MyObject { + #[graphql(default = 10)] + a: i32, + b: bool, + #[graphql(skip)] + c: String, + } + + assert_eq!(::type_name(), "MyObjectInput"); + assert_eq!(::type_name(), "MyObj"); +} + #[test] #[should_panic] pub fn test_both_input_output_with_same_name() {