diff --git a/README.md b/README.md index 320388cc..6dda5ecb 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ graphql_enum!(Episode { Episode::Jedi => "JEDI", }); -graphql_object!(Human: () as "Human" |&self| { +graphql_object!(Human: () |&self| { description: "A humanoid creature in the Star Wars universe" // Field resolver methods look almost like ordinary methods. The macro picks diff --git a/src/executor_tests/introspection.rs b/src/executor_tests/introspection.rs index 2fff71a0..e9cdc672 100644 --- a/src/executor_tests/introspection.rs +++ b/src/executor_tests/introspection.rs @@ -41,7 +41,7 @@ graphql_interface!(Interface: () as "SampleInterface" |&self| { } }); -graphql_object!(Root: () as "Root" |&self| { +graphql_object!(Root: () |&self| { description: "The root query object in the schema" interfaces: [Interface] diff --git a/src/lib.rs b/src/lib.rs index 4c69723b..5d647e1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,7 +43,7 @@ struct Database { users: HashMap } // object to provide e.g. database access to the field accessors. // // In this example, we use the Database struct as our context. -graphql_object!(User: Database as "User" |&self| { +graphql_object!(User: Database |&self| { // Expose a simple field as a GraphQL string. field id() -> &String { @@ -76,7 +76,7 @@ graphql_object!(User: Database as "User" |&self| { // The context object is passed down to all referenced types - all your exposed // types need to have the same context type. -graphql_object!(QueryRoot: Database as "Query" |&self| { +graphql_object!(QueryRoot: Database |&self| { // Arguments work just like they do on functions. field user(&mut executor, id: String) -> Option<&User> { @@ -112,7 +112,7 @@ use juniper::iron_handlers::GraphQLHandler; # struct QueryRoot; # struct Database { users: HashMap } # -# graphql_object!(User: Database as "User" |&self| { +# graphql_object!(User: Database |&self| { # field id() -> FieldResult<&String> { # Ok(&self.id) # } @@ -128,7 +128,7 @@ use juniper::iron_handlers::GraphQLHandler; # } # }); # -# graphql_object!(QueryRoot: Database as "Query" |&self| { +# graphql_object!(QueryRoot: Database |&self| { # field user(&mut executor, id: String) -> FieldResult> { # Ok(executor.context().users.get(&id)) # } diff --git a/src/macros/object.rs b/src/macros/object.rs index 22079547..6509a207 100644 --- a/src/macros/object.rs +++ b/src/macros/object.rs @@ -13,7 +13,7 @@ The simplest case exposes fields on a struct: # #[macro_use] extern crate juniper; struct User { id: String, name: String, group_ids: Vec } -graphql_object!(User: () as "User" |&self| { +graphql_object!(User: () |&self| { field id() -> &String { &self.id } @@ -42,7 +42,7 @@ arguments: # #[macro_use] extern crate juniper; struct User { id: String, name: String, group_ids: Vec } -graphql_object!(User: () as "User" |&self| { +graphql_object!(User: () |&self| { description: "A user in the database" field id() -> &String as "The user's unique identifier" { @@ -105,7 +105,7 @@ graphql_interface!(<'a> &'a Interface: () as "Interface" |&self| { } }); -graphql_object!(Implementor: () as "Implementor" |&self| { +graphql_object!(Implementor: () |&self| { field id() -> &str { &self.id } interfaces: [&Interface] @@ -130,7 +130,7 @@ continue executing despite some fields failing. # use juniper::FieldResult; struct User { id: String } -graphql_object!(User: () as "User" |&self| { +graphql_object!(User: () |&self| { field id() -> FieldResult<&String> { Ok(&self.id) } diff --git a/src/macros/tests/args.rs b/src/macros/tests/args.rs index 12396943..9afee3f0 100644 --- a/src/macros/tests/args.rs +++ b/src/macros/tests/args.rs @@ -18,7 +18,7 @@ Syntax to validate: */ -graphql_object!(Root: () as "Root" |&self| { +graphql_object!(Root: () |&self| { field simple() -> i64 { 0 } field exec_arg(&mut executor) -> i64 { 0 } field exec_arg_and_more(&mut executor, arg: i64) -> i64 { 0 } diff --git a/src/macros/tests/enums.rs b/src/macros/tests/enums.rs index 0782e62d..0576ecf9 100644 --- a/src/macros/tests/enums.rs +++ b/src/macros/tests/enums.rs @@ -57,7 +57,7 @@ graphql_enum!(EnumDeprecation { EnumDeprecation::Bar => "BAR" as "The BAR value" deprecated "Please don't use BAR any more", }); -graphql_object!(Root: () as "Root" |&self| { +graphql_object!(Root: () |&self| { field default_name() -> DefaultName { DefaultName::Foo } field named() -> Named { Named::Foo } field no_trailing_comma() -> NoTrailingComma { NoTrailingComma::Foo } diff --git a/src/macros/tests/field.rs b/src/macros/tests/field.rs index 8e7dd607..78ee2a6c 100644 --- a/src/macros/tests/field.rs +++ b/src/macros/tests/field.rs @@ -17,7 +17,7 @@ Syntax to validate: */ -graphql_object!(Root: () as "Root" |&self| { +graphql_object!(Root: () |&self| { field simple() -> i64 { 0 } field description() -> i64 as "Field description" { 0 } @@ -31,7 +31,7 @@ graphql_object!(Root: () as "Root" |&self| { interfaces: [Interface] }); -graphql_interface!(Interface: () as "Interface" |&self| { +graphql_interface!(Interface: () |&self| { field simple() -> i64 { 0 } field description() -> i64 as "Field description" { 0 } diff --git a/src/macros/tests/input_object.rs b/src/macros/tests/input_object.rs index 0e8d1605..28835e56 100644 --- a/src/macros/tests/input_object.rs +++ b/src/macros/tests/input_object.rs @@ -48,7 +48,7 @@ graphql_input_object!( } ); -graphql_object!(Root: () as "Root" |&self| { +graphql_object!(Root: () |&self| { field test_field( a1: DefaultName, a2: NoTrailingComma, diff --git a/src/macros/tests/interface.rs b/src/macros/tests/interface.rs index db7fa027..6afa25c8 100644 --- a/src/macros/tests/interface.rs +++ b/src/macros/tests/interface.rs @@ -19,7 +19,7 @@ Syntax to validate: struct Concrete; -struct DefaultName; +struct CustomName; #[allow(dead_code)] struct WithLifetime<'a> { data: PhantomData<&'a i64> } @@ -42,7 +42,7 @@ graphql_object!(Concrete: () |&self| { field simple() -> i64 { 0 } }); -graphql_interface!(DefaultName: () |&self| { +graphql_interface!(CustomName: () as "ACustomNamedInterface" |&self| { field simple() -> i64 { 0 } instance_resolvers: |_| { Concrete => Some(Concrete) } @@ -60,7 +60,7 @@ graphql_interface!( WithGenerics: () as "WithGenerics" |&self| { }); -graphql_interface!(DescriptionFirst: () as "DescriptionFirst" |&self| { +graphql_interface!(DescriptionFirst: () |&self| { description: "A description" field simple() -> i64 { 0 } @@ -68,7 +68,7 @@ graphql_interface!(DescriptionFirst: () as "DescriptionFirst" |&self| { instance_resolvers: |_| { Concrete => Some(Concrete) } }); -graphql_interface!(FieldsFirst: () as "FieldsFirst" |&self| { +graphql_interface!(FieldsFirst: () |&self| { field simple() -> i64 { 0 } description: "A description" @@ -76,7 +76,7 @@ graphql_interface!(FieldsFirst: () as "FieldsFirst" |&self| { instance_resolvers: |_| { Concrete => Some(Concrete) } }); -graphql_interface!(InterfacesFirst: () as "InterfacesFirst" |&self| { +graphql_interface!(InterfacesFirst: () |&self| { instance_resolvers: |_| { Concrete => Some(Concrete) } field simple() -> i64 { 0 } @@ -84,7 +84,7 @@ graphql_interface!(InterfacesFirst: () as "InterfacesFirst" |&self| { description: "A description" }); -graphql_interface!(CommasWithTrailing: () as "CommasWithTrailing" |&self| { +graphql_interface!(CommasWithTrailing: () |&self| { instance_resolvers: |_| { Concrete => Some(Concrete) }, field simple() -> i64 { 0 }, @@ -93,7 +93,7 @@ graphql_interface!(CommasWithTrailing: () as "CommasWithTrailing" |&self| { }); -graphql_interface!(CommasOnMeta: () as "CommasOnMeta" |&self| { +graphql_interface!(CommasOnMeta: () |&self| { instance_resolvers: |_| { Concrete => Some(Concrete) } description: "A description", @@ -101,7 +101,7 @@ graphql_interface!(CommasOnMeta: () as "CommasOnMeta" |&self| { }); -graphql_interface!(ResolversWithTrailingComma: () as "ResolversWithTrailingComma" |&self| { +graphql_interface!(ResolversWithTrailingComma: () |&self| { instance_resolvers: |_| { Concrete => Some(Concrete), } description: "A description", @@ -109,7 +109,7 @@ graphql_interface!(ResolversWithTrailingComma: () as "ResolversWithTrailingComma }); graphql_object!(<'a> Root: () as "Root" |&self| { - field default_name() -> DefaultName { DefaultName {} } + field custom_name() -> CustomName { CustomName {} } field with_lifetime() -> WithLifetime<'a> { WithLifetime { data: PhantomData } } field with_generics() -> WithGenerics { WithGenerics { data: 123 } } @@ -167,9 +167,9 @@ fn run_type_info_query(type_name: &str, f: F) } #[test] -fn introspect_default_name() { - run_type_info_query("DefaultName", |object, fields| { - assert_eq!(object.get("name"), Some(&Value::string("DefaultName"))); +fn introspect_custom_name() { + run_type_info_query("ACustomNamedInterface", |object, fields| { + assert_eq!(object.get("name"), Some(&Value::string("ACustomNamedInterface"))); assert_eq!(object.get("description"), Some(&Value::null())); assert!(fields.contains(&Value::object(vec![ diff --git a/src/macros/tests/object.rs b/src/macros/tests/object.rs index 41c59308..63d8815d 100644 --- a/src/macros/tests/object.rs +++ b/src/macros/tests/object.rs @@ -18,7 +18,7 @@ Syntax to validate: struct Interface; -struct DefaultName; +struct CustomName; #[allow(dead_code)] struct WithLifetime<'a> { data: PhantomData<&'a i64> } @@ -35,7 +35,7 @@ struct CommasOnMeta; struct Root; -graphql_object!(DefaultName: () |&self| { +graphql_object!(CustomName: () as "ACustomNamedType" |&self| { field simple() -> i64 { 0 } }); @@ -49,7 +49,7 @@ graphql_object!( WithGenerics: () as "WithGenerics" |&self| { }); -graphql_interface!(Interface: () as "Interface" |&self| { +graphql_interface!(Interface: () |&self| { field simple() -> i64 { 0 } instance_resolvers: |_| { @@ -57,7 +57,7 @@ graphql_interface!(Interface: () as "Interface" |&self| { } }); -graphql_object!(DescriptionFirst: () as "DescriptionFirst" |&self| { +graphql_object!(DescriptionFirst: () |&self| { description: "A description" field simple() -> i64 { 0 } @@ -65,7 +65,7 @@ graphql_object!(DescriptionFirst: () as "DescriptionFirst" |&self| { interfaces: [Interface] }); -graphql_object!(FieldsFirst: () as "FieldsFirst" |&self| { +graphql_object!(FieldsFirst: () |&self| { field simple() -> i64 { 0 } description: "A description" @@ -73,7 +73,7 @@ graphql_object!(FieldsFirst: () as "FieldsFirst" |&self| { interfaces: [Interface] }); -graphql_object!(InterfacesFirst: () as "InterfacesFirst" |&self| { +graphql_object!(InterfacesFirst: ()|&self| { interfaces: [Interface] field simple() -> i64 { 0 } @@ -81,7 +81,7 @@ graphql_object!(InterfacesFirst: () as "InterfacesFirst" |&self| { description: "A description" }); -graphql_object!(CommasWithTrailing: () as "CommasWithTrailing" |&self| { +graphql_object!(CommasWithTrailing: () |&self| { interfaces: [Interface], field simple() -> i64 { 0 }, @@ -90,7 +90,7 @@ graphql_object!(CommasWithTrailing: () as "CommasWithTrailing" |&self| { }); -graphql_object!(CommasOnMeta: () as "CommasOnMeta" |&self| { +graphql_object!(CommasOnMeta: () |&self| { interfaces: [Interface], description: "A description", @@ -98,7 +98,7 @@ graphql_object!(CommasOnMeta: () as "CommasOnMeta" |&self| { }); graphql_object!(<'a> Root: () as "Root" |&self| { - field default_name() -> DefaultName { DefaultName {} } + field custom_name() -> CustomName { CustomName {} } field with_lifetime() -> WithLifetime<'a> { WithLifetime { data: PhantomData } } field with_generics() -> WithGenerics { WithGenerics { data: 123 } } @@ -155,9 +155,9 @@ fn run_type_info_query(type_name: &str, f: F) } #[test] -fn introspect_default_name() { - run_type_info_query("DefaultName", |object, fields| { - assert_eq!(object.get("name"), Some(&Value::string("DefaultName"))); +fn introspect_custom_name() { + run_type_info_query("ACustomNamedType", |object, fields| { + assert_eq!(object.get("name"), Some(&Value::string("ACustomNamedType"))); assert_eq!(object.get("description"), Some(&Value::null())); assert_eq!(object.get("interfaces"), Some(&Value::list(vec![]))); diff --git a/src/macros/tests/scalar.rs b/src/macros/tests/scalar.rs index bc1fb2ef..0cb832ca 100644 --- a/src/macros/tests/scalar.rs +++ b/src/macros/tests/scalar.rs @@ -61,7 +61,7 @@ graphql_scalar!(ScalarDescription { } }); -graphql_object!(Root: () as "Root" |&self| { +graphql_object!(Root: () |&self| { field default_name() -> DefaultName { DefaultName(0) } field other_order() -> OtherOrder { OtherOrder(0) } field named() -> Named { Named(0) } diff --git a/src/macros/tests/union.rs b/src/macros/tests/union.rs index f8df8556..12d2c616 100644 --- a/src/macros/tests/union.rs +++ b/src/macros/tests/union.rs @@ -19,7 +19,7 @@ Syntax to validate: struct Concrete; -enum DefaultName { Concrete(Concrete) } +enum CustomName { Concrete(Concrete) } enum WithLifetime<'a> { Int(PhantomData<&'a i64>) } enum WithGenerics { Generic(T) } @@ -36,9 +36,9 @@ graphql_object!(Concrete: () |&self| { field simple() -> i64 { 123 } }); -graphql_union!(DefaultName: () |&self| { +graphql_union!(CustomName: () as "ACustomNamedUnion" |&self| { instance_resolvers: |&_| { - &Concrete => match *self { DefaultName::Concrete(ref c) => Some(c) } + &Concrete => match *self { CustomName::Concrete(ref c) => Some(c) } } }); @@ -83,7 +83,7 @@ graphql_union!(ResolversWithTrailingComma: () |&self| { }); graphql_object!(<'a> Root: () as "Root" |&self| { - field default_name() -> DefaultName { DefaultName::Concrete(Concrete) } + field custom_name() -> CustomName { CustomName::Concrete(Concrete) } field with_lifetime() -> WithLifetime<'a> { WithLifetime::Int(PhantomData) } field with_generics() -> WithGenerics { WithGenerics::Generic(123) } field description_first() -> DescriptionFirst { DescriptionFirst::Concrete(Concrete) } @@ -135,9 +135,9 @@ fn run_type_info_query(type_name: &str, f: F) #[test] -fn introspect_default_name() { - run_type_info_query("DefaultName", |union, possible_types| { - assert_eq!(union.get("name"), Some(&Value::string("DefaultName"))); +fn introspect_custom_name() { + run_type_info_query("ACustomNamedUnion", |union, possible_types| { + assert_eq!(union.get("name"), Some(&Value::string("ACustomNamedUnion"))); assert_eq!(union.get("description"), Some(&Value::null())); assert!(possible_types.contains(&Value::object(vec![