Bugfix argument description handling

This commit is contained in:
Magnus Hallin 2016-09-22 21:50:19 +02:00
parent 14ea90b790
commit ac51f09873
2 changed files with 61 additions and 4 deletions

View file

@ -54,7 +54,7 @@ graphql_object!(Root: () as "Root" |&self| {
field sample_scalar( field sample_scalar(
first: i64 as "The first number", first: i64 as "The first number",
second = 123: i64 as "The second number" second = 123: i64 as "The second number"
) -> FieldResult<Scalar> { ) -> FieldResult<Scalar> as "A sample scalar field on the object" {
Ok(Scalar(first + second)) Ok(Scalar(first + second))
} }
}); });
@ -251,6 +251,19 @@ fn object_introspection() {
description description
args { args {
name name
description
type {
name
kind
ofType {
name
kind
ofType {
name
}
}
}
defaultValue
} }
type { type {
name name
@ -306,6 +319,8 @@ fn object_introspection() {
assert_eq!(fields.len(), 5); // The two fields, __typename, __type, __schema assert_eq!(fields.len(), 5); // The two fields, __typename, __type, __schema
println!("Fields: {:#?}", fields);
assert!(fields.contains(&Value::object(vec![ assert!(fields.contains(&Value::object(vec![
("name", Value::string("sampleEnum")), ("name", Value::string("sampleEnum")),
("description", Value::null()), ("description", Value::null()),
@ -321,6 +336,47 @@ fn object_introspection() {
("isDeprecated", Value::boolean(false)), ("isDeprecated", Value::boolean(false)),
("deprecationReason", Value::null()), ("deprecationReason", Value::null()),
].into_iter().collect()))); ].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] #[test]

View file

@ -113,8 +113,8 @@ macro_rules! __graphql__args {
) => { ) => {
$base.argument($reg.arg_with_default::<$t>( $base.argument($reg.arg_with_default::<$t>(
&$crate::to_snake_case(stringify!($name)), &$crate::to_snake_case(stringify!($name)),
&__graphql__args!(@as_expr, $default))) &__graphql__args!(@as_expr, $default))
.description($desc) .description($desc))
}; };
( (
@ -126,7 +126,8 @@ macro_rules! __graphql__args {
$reg, $reg,
$base.argument($reg.arg_with_default::<$t>( $base.argument($reg.arg_with_default::<$t>(
&$crate::to_snake_case(stringify!($name)), &$crate::to_snake_case(stringify!($name)),
&__graphql__args!(@as_expr, $default))), &__graphql__args!(@as_expr, $default))
.description($desc)),
( $($rest)* )) ( $($rest)* ))
}; };