From ac51f09873214b078489d0f6e17d5c55262845d2 Mon Sep 17 00:00:00 2001 From: Magnus Hallin Date: Thu, 22 Sep 2016 21:50:19 +0200 Subject: [PATCH] Bugfix argument description handling --- src/executor_tests/introspection.rs | 58 ++++++++++++++++++++++++++++- src/macros/args.rs | 7 ++-- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/executor_tests/introspection.rs b/src/executor_tests/introspection.rs index 6238dd75..70058a7a 100644 --- a/src/executor_tests/introspection.rs +++ b/src/executor_tests/introspection.rs @@ -54,7 +54,7 @@ graphql_object!(Root: () as "Root" |&self| { field sample_scalar( first: i64 as "The first number", second = 123: i64 as "The second number" - ) -> FieldResult { + ) -> FieldResult as "A sample scalar field on the object" { Ok(Scalar(first + second)) } }); @@ -251,6 +251,19 @@ fn object_introspection() { description args { name + description + type { + name + kind + ofType { + name + kind + ofType { + name + } + } + } + defaultValue } type { name @@ -306,6 +319,8 @@ fn object_introspection() { assert_eq!(fields.len(), 5); // The two fields, __typename, __type, __schema + println!("Fields: {:#?}", fields); + assert!(fields.contains(&Value::object(vec![ ("name", Value::string("sampleEnum")), ("description", Value::null()), @@ -321,6 +336,47 @@ fn object_introspection() { ("isDeprecated", Value::boolean(false)), ("deprecationReason", Value::null()), ].into_iter().collect()))); + + assert!(fields.contains(&Value::object(vec![ + ("name", Value::string("sampleScalar")), + ("description", Value::string("A sample scalar field on the object")), + ("args", Value::list(vec![ + Value::object(vec![ + ("name", Value::string("first")), + ("description", Value::string("The first number")), + ("type", Value::object(vec![ + ("name", Value::null()), + ("kind", Value::string("NON_NULL")), + ("ofType", Value::object(vec![ + ("name", Value::string("Int")), + ("kind", Value::string("SCALAR")), + ("ofType", Value::null()), + ].into_iter().collect())), + ].into_iter().collect())), + ("defaultValue", Value::null()), + ].into_iter().collect()), + Value::object(vec![ + ("name", Value::string("second")), + ("description", Value::string("The second number")), + ("type", Value::object(vec![ + ("name", Value::string("Int")), + ("kind", Value::string("SCALAR")), + ("ofType", Value::null()), + ].into_iter().collect())), + ("defaultValue", Value::string("123")), + ].into_iter().collect()), + ])), + ("type", Value::object(vec![ + ("name", Value::null()), + ("kind", Value::string("NON_NULL")), + ("ofType", Value::object(vec![ + ("name", Value::string("SampleScalar")), + ("kind", Value::string("SCALAR")), + ].into_iter().collect())), + ].into_iter().collect())), + ("isDeprecated", Value::boolean(false)), + ("deprecationReason", Value::null()), + ].into_iter().collect()))); } #[test] diff --git a/src/macros/args.rs b/src/macros/args.rs index cc06d7fa..b8afd927 100644 --- a/src/macros/args.rs +++ b/src/macros/args.rs @@ -113,8 +113,8 @@ macro_rules! __graphql__args { ) => { $base.argument($reg.arg_with_default::<$t>( &$crate::to_snake_case(stringify!($name)), - &__graphql__args!(@as_expr, $default))) - .description($desc) + &__graphql__args!(@as_expr, $default)) + .description($desc)) }; ( @@ -126,7 +126,8 @@ macro_rules! __graphql__args { $reg, $base.argument($reg.arg_with_default::<$t>( &$crate::to_snake_case(stringify!($name)), - &__graphql__args!(@as_expr, $default))), + &__graphql__args!(@as_expr, $default)) + .description($desc)), ( $($rest)* )) };