diff --git a/docs/book/content/advanced/introspection.md b/docs/book/content/advanced/introspection.md index 66949761..a8675b03 100644 --- a/docs/book/content/advanced/introspection.md +++ b/docs/book/content/advanced/introspection.md @@ -44,7 +44,7 @@ impl juniper::Context for Context {} struct Query; -#[juniper::impl_object( +#[juniper::object( Context = Context, )] impl Query { diff --git a/docs/book/content/advanced/non_struct_objects.md b/docs/book/content/advanced/non_struct_objects.md index af6b7342..bb23c28a 100644 --- a/docs/book/content/advanced/non_struct_objects.md +++ b/docs/book/content/advanced/non_struct_objects.md @@ -23,7 +23,7 @@ enum SignUpResult { Error(Vec), } -#[juniper::impl_object] +#[juniper::object] impl SignUpResult { fn user(&self) -> Option<&User> { match *self { diff --git a/docs/book/content/advanced/objects_and_generics.md b/docs/book/content/advanced/objects_and_generics.md index 9c91734b..87b98437 100644 --- a/docs/book/content/advanced/objects_and_generics.md +++ b/docs/book/content/advanced/objects_and_generics.md @@ -25,7 +25,7 @@ struct ValidationError { # #[allow(dead_code)] struct MutationResult(Result>); -#[juniper::impl_object( +#[juniper::object( name = "UserResult", )] impl MutationResult { @@ -38,7 +38,7 @@ impl MutationResult { } } -#[juniper::impl_object( +#[juniper::object( name = "ForumPostResult", )] impl MutationResult { diff --git a/docs/book/content/quickstart.md b/docs/book/content/quickstart.md index c5e2c69b..21917716 100644 --- a/docs/book/content/quickstart.md +++ b/docs/book/content/quickstart.md @@ -20,7 +20,7 @@ naturally map to GraphQL features, such as `Option`, `Vec`, `Box`, For more advanced mappings, Juniper provides multiple macros to map your Rust types to a GraphQL schema. The most important one is the -[impl_object][jp_impl_object] procedural macro that is used for declaring an object with +[object][jp_object] procedural macro that is used for declaring an object with resolvers, which you will use for the `Query` and `Mutation` roots. ```rust @@ -60,7 +60,7 @@ struct NewHuman { } // Now, we create our root Query and Mutation types with resolvers by using the -// impl_object macro. +// object macro. // Objects can have contexts that allow accessing shared state like a database // pool. @@ -74,7 +74,7 @@ impl juniper::Context for Context {} struct Query; -#[juniper::impl_object( +#[juniper::object( // Here we specify the context type for the object. // We need to do this in every type that // needs access to the context. @@ -105,7 +105,7 @@ impl Query { struct Mutation; -#[juniper::impl_object( +#[juniper::object( Context = Context, )] impl Mutation { @@ -156,7 +156,7 @@ impl juniper::Context for Ctx {} struct Query; -#[juniper::impl_object( +#[juniper::object( Context = Ctx, )] impl Query { @@ -198,4 +198,4 @@ fn main() { [rocket]: servers/rocket.md [iron]: servers/iron.md [tutorial]: ./tutorial.html -[jp_obj_macro]: https://docs.rs/juniper/latest/juniper/macro.impl_object.html +[jp_obj_macro]: https://docs.rs/juniper/latest/juniper/macro.object.html diff --git a/docs/book/content/schema/schemas_and_mutations.md b/docs/book/content/schema/schemas_and_mutations.md index c2a90417..543bc899 100644 --- a/docs/book/content/schema/schemas_and_mutations.md +++ b/docs/book/content/schema/schemas_and_mutations.md @@ -20,14 +20,14 @@ object somewhere but never references it, it will not be exposed in a schema. ## The query root The query root is just a GraphQL object. You define it like any other GraphQL -object in Juniper, most commonly using the `impl_object` proc macro: +object in Juniper, most commonly using the `object` proc macro: ```rust # use juniper::FieldResult; # #[derive(juniper::GraphQLObject)] struct User { name: String } struct Root; -#[juniper::impl_object] +#[juniper::object] impl Root { fn userWithUsername(username: String) -> FieldResult> { // Look up user in database... @@ -48,7 +48,7 @@ usually performs some mutating side-effect, such as updating a database. # #[derive(juniper::GraphQLObject)] struct User { name: String } struct Mutations; -#[juniper::impl_object] +#[juniper::object] impl Mutations { fn signUpUser(name: String, email: String) -> FieldResult { // Validate inputs and save user in database... diff --git a/docs/book/content/servers/iron.md b/docs/book/content/servers/iron.md index ec428889..da76ba75 100644 --- a/docs/book/content/servers/iron.md +++ b/docs/book/content/servers/iron.md @@ -47,7 +47,7 @@ fn context_factory(_: &mut Request) -> IronResult<()> { struct Root; -#[juniper::impl_object] +#[juniper::object] impl Root { fn foo() -> String { "Bar".to_owned() @@ -99,7 +99,7 @@ fn context_factory(req: &mut Request) -> IronResult { struct Root; -#[juniper::impl_object( +#[juniper::object( Context = Context, )] impl Root { diff --git a/docs/book/content/types/input_objects.md b/docs/book/content/types/input_objects.md index 837a3aed..0d5aa45b 100644 --- a/docs/book/content/types/input_objects.md +++ b/docs/book/content/types/input_objects.md @@ -14,7 +14,7 @@ struct Coordinate { struct Root; # #[derive(juniper::GraphQLObject)] struct User { name: String } -#[juniper::impl_object] +#[juniper::object] impl Root { fn users_at_location(coordinate: Coordinate, radius: f64) -> Vec { // Send coordinate to database @@ -45,7 +45,7 @@ struct WorldCoordinate { struct Root; # #[derive(juniper::GraphQLObject)] struct User { name: String } -#[juniper::impl_object] +#[juniper::object] impl Root { fn users_at_location(coordinate: WorldCoordinate, radius: f64) -> Vec { // Send coordinate to database diff --git a/docs/book/content/types/objects/complex_fields.md b/docs/book/content/types/objects/complex_fields.md index 81399756..771fba12 100644 --- a/docs/book/content/types/objects/complex_fields.md +++ b/docs/book/content/types/objects/complex_fields.md @@ -2,7 +2,7 @@ If you've got a struct that can't be mapped directly to GraphQL, that contains computed fields or circular structures, you have to use a more powerful tool: -the `impl_object` procedural macro. This macro lets you define GraphQL object +the `object` procedural macro. This macro lets you define GraphQL object fields in a Rust `impl` block for a type. Continuing with the example from the last chapter, this is how you would define `Person` using the macro: @@ -14,7 +14,7 @@ struct Person { age: i32, } -#[juniper::impl_object] +#[juniper::object] impl Person { fn name(&self) -> &str { self.name.as_str() @@ -43,7 +43,7 @@ struct House { inhabitants: Vec, } -#[juniper::impl_object] +#[juniper::object] impl House { // Creates the field inhabitantWithName(name), returning a nullable person fn inhabitant_with_name(&self, name: String) -> Option<&Person> { @@ -70,7 +70,7 @@ struct Person { website_url: String, } -#[juniper::impl_object( +#[juniper::object( // With this attribtue you can change the public GraphQL name of the type. name = "PersonObject", )] @@ -96,4 +96,4 @@ GraphQL fields expose more features than Rust's standard method syntax gives us: * Per-argument descriptions These, and more features, are described more thorougly in [the reference -documentation](https://docs.rs/juniper/latest/juniper/macro.impl_object.html). +documentation](https://docs.rs/juniper/latest/juniper/macro.object.html). diff --git a/docs/book/content/types/objects/error_handling.md b/docs/book/content/types/objects/error_handling.md index 8e4b047d..fe136fba 100644 --- a/docs/book/content/types/objects/error_handling.md +++ b/docs/book/content/types/objects/error_handling.md @@ -25,7 +25,7 @@ struct Example { filename: PathBuf, } -#[juniper::impl_object] +#[juniper::object] impl Example { fn contents() -> FieldResult { let mut file = File::open(&self.filename)?; @@ -143,7 +143,7 @@ struct Example { whatever: Option, } -#[juniper::impl_object] +#[juniper::object] impl Example { fn whatever() -> Result { if let Some(value) = self.whatever { diff --git a/docs/book/content/types/objects/using_contexts.md b/docs/book/content/types/objects/using_contexts.md index ef210c8b..676dc6a0 100644 --- a/docs/book/content/types/objects/using_contexts.md +++ b/docs/book/content/types/objects/using_contexts.md @@ -57,7 +57,7 @@ struct User { // Assign Database as the context type for User -#[juniper::impl_object( +#[juniper::object( Context = Database, )] impl User { diff --git a/integration_tests/juniper_tests/src/codegen/derive_object.rs b/integration_tests/juniper_tests/src/codegen/derive_object.rs index ac78b521..88c5cdc1 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_object.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_object.rs @@ -80,7 +80,7 @@ struct WithCustomContext { a: bool, } -#[juniper::impl_object] +#[juniper::object] impl Query { fn obj() -> Obj { Obj { diff --git a/integration_tests/juniper_tests/src/custom_scalar.rs b/integration_tests/juniper_tests/src/custom_scalar.rs index 07c37f72..a08c5746 100644 --- a/integration_tests/juniper_tests/src/custom_scalar.rs +++ b/integration_tests/juniper_tests/src/custom_scalar.rs @@ -151,7 +151,7 @@ juniper::graphql_scalar!(i64 as "Long" where Scalar = MyScalarValue { struct TestType; -#[juniper::impl_object( +#[juniper::object( Scalar = MyScalarValue )] impl TestType { diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index 0a0119fa..d3e3660a 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -1,9 +1,9 @@ # master -### impl_object macro +### object macro The `graphql_object!` macro is deprecated and will be removed in the future. -It is replaced by the new [impl_object](https://docs.rs/juniper/latest/juniper/macro.impl_object.html) procedural macro. +It is replaced by the new [object](https://docs.rs/juniper/latest/juniper/macro.object.html) procedural macro. [#333](https://github.com/graphql-rust/juniper/pull/333) diff --git a/juniper/src/executor_tests/directives.rs b/juniper/src/executor_tests/directives.rs index e5648f3e..04727687 100644 --- a/juniper/src/executor_tests/directives.rs +++ b/juniper/src/executor_tests/directives.rs @@ -5,7 +5,7 @@ use crate::value::{DefaultScalarValue, Object, Value}; struct TestType; -#[crate::impl_object_internal] +#[crate::object_internal] impl TestType { fn a() -> &str { "a" diff --git a/juniper/src/executor_tests/enums.rs b/juniper/src/executor_tests/enums.rs index 6738f531..7e9cec1b 100644 --- a/juniper/src/executor_tests/enums.rs +++ b/juniper/src/executor_tests/enums.rs @@ -17,7 +17,7 @@ enum Color { } struct TestType; -#[crate::impl_object_internal] +#[crate::object_internal] impl TestType { fn to_string(color: Color) -> String { format!("Color::{:?}", color) diff --git a/juniper/src/executor_tests/executor.rs b/juniper/src/executor_tests/executor.rs index e8fd0870..524c7402 100644 --- a/juniper/src/executor_tests/executor.rs +++ b/juniper/src/executor_tests/executor.rs @@ -7,7 +7,7 @@ mod field_execution { struct DataType; struct DeepDataType; - #[crate::impl_object_internal] + #[crate::object_internal] impl DataType { fn a() -> &str { "Apple" @@ -37,7 +37,7 @@ mod field_execution { } } - #[crate::impl_object_internal] + #[crate::object_internal] impl DeepDataType { fn a() -> &str { "Already Been Done" @@ -162,7 +162,7 @@ mod merge_parallel_fragments { struct Type; - #[crate::impl_object_internal] + #[crate::object_internal] impl Type { fn a() -> &str { "Apple" @@ -246,7 +246,7 @@ mod merge_parallel_inline_fragments { struct Type; struct Other; - #[crate::impl_object_internal] + #[crate::object_internal] impl Type { fn a() -> &str { "Apple" @@ -265,7 +265,7 @@ mod merge_parallel_inline_fragments { } } - #[crate::impl_object_internal] + #[crate::object_internal] impl Other { fn a() -> &str { "Apple" @@ -396,7 +396,7 @@ mod threads_context_correctly { impl Context for TestContext {} - #[crate::impl_object_internal( + #[crate::object_internal( Context = TestContext, )] impl Schema { @@ -462,7 +462,7 @@ mod dynamic_context_switching { struct ItemRef; - #[crate::impl_object_internal(Context = OuterContext)] + #[crate::object_internal(Context = OuterContext)] impl Schema { fn item_opt(context: &OuterContext, key: i32) -> Option<(&InnerContext, ItemRef)> { executor.context().items.get(&key).map(|c| (c, ItemRef)) @@ -492,7 +492,7 @@ mod dynamic_context_switching { } } - #[crate::impl_object_internal(Context = InnerContext)] + #[crate::object_internal(Context = InnerContext)] impl ItemRef { fn value(context: &InnerContext) -> String { context.value.clone() @@ -801,7 +801,7 @@ mod propagates_errors_to_nullable_fields { } } - #[crate::impl_object_internal] + #[crate::object_internal] impl Schema { fn inner() -> Inner { Inner @@ -814,7 +814,7 @@ mod propagates_errors_to_nullable_fields { } } - #[crate::impl_object_internal] + #[crate::object_internal] impl Inner { fn nullable_field() -> Option { Some(Inner) @@ -1068,7 +1068,7 @@ mod named_operations { struct Schema; - #[crate::impl_object_internal] + #[crate::object_internal] impl Schema { fn a() -> &str { "b" diff --git a/juniper/src/executor_tests/interfaces_unions.rs b/juniper/src/executor_tests/interfaces_unions.rs index 851d7197..d5ab086b 100644 --- a/juniper/src/executor_tests/interfaces_unions.rs +++ b/juniper/src/executor_tests/interfaces_unions.rs @@ -37,7 +37,7 @@ mod interface { } } - #[crate::impl_object_internal( + #[crate::object_internal( interfaces = [&Pet] )] impl Dog { @@ -63,7 +63,7 @@ mod interface { } } - #[crate::impl_object_internal( + #[crate::object_internal( interfaces = [&Pet] )] impl Cat { @@ -79,7 +79,7 @@ mod interface { pets: Vec>, } - #[crate::impl_object_internal] + #[crate::object_internal] impl Schema { fn pets(&self) -> Vec<&Pet> { self.pets.iter().map(|p| p.as_ref()).collect() @@ -188,7 +188,7 @@ mod union { } } - #[crate::impl_object_internal] + #[crate::object_internal] impl Dog { fn name(&self) -> &str { &self.name @@ -209,7 +209,7 @@ mod union { } } - #[crate::impl_object_internal] + #[crate::object_internal] impl Cat { fn name(&self) -> &str { &self.name @@ -223,7 +223,7 @@ mod union { pets: Vec>, } - #[crate::impl_object_internal] + #[crate::object_internal] impl Schema { fn pets(&self) -> Vec<&Pet> { self.pets.iter().map(|p| p.as_ref()).collect() diff --git a/juniper/src/executor_tests/introspection/enums.rs b/juniper/src/executor_tests/introspection/enums.rs index c9e88b6a..0ffee96c 100644 --- a/juniper/src/executor_tests/introspection/enums.rs +++ b/juniper/src/executor_tests/introspection/enums.rs @@ -64,7 +64,7 @@ enum EnumDeprecation { struct Root; -#[crate::impl_object_internal] +#[crate::object_internal] impl Root { fn default_name() -> DefaultName { DefaultName::Foo diff --git a/juniper/src/executor_tests/introspection/input_object.rs b/juniper/src/executor_tests/introspection/input_object.rs index 388fa556..1cf1294e 100644 --- a/juniper/src/executor_tests/introspection/input_object.rs +++ b/juniper/src/executor_tests/introspection/input_object.rs @@ -79,7 +79,7 @@ struct FieldWithDefaults { field_two: i32, } -#[crate::impl_object_internal] +#[crate::object_internal] impl Root { fn test_field( a1: DefaultName, diff --git a/juniper/src/executor_tests/introspection/mod.rs b/juniper/src/executor_tests/introspection/mod.rs index b93fccd2..ff9f28f6 100644 --- a/juniper/src/executor_tests/introspection/mod.rs +++ b/juniper/src/executor_tests/introspection/mod.rs @@ -52,7 +52,7 @@ graphql_interface!(Interface: () as "SampleInterface" |&self| { }); /// The root query object in the schema -#[crate::impl_object_internal( +#[crate::object_internal( interfaces = [&Interface] Scalar = crate::DefaultScalarValue, )] diff --git a/juniper/src/executor_tests/variables.rs b/juniper/src/executor_tests/variables.rs index 0bf99854..7b8dd791 100644 --- a/juniper/src/executor_tests/variables.rs +++ b/juniper/src/executor_tests/variables.rs @@ -62,7 +62,7 @@ struct InputWithDefaults { a: i32, } -#[crate::impl_object_internal] +#[crate::object_internal] impl TestType { fn field_with_object_input(input: Option) -> String { format!("{:?}", input) diff --git a/juniper/src/integrations/chrono.rs b/juniper/src/integrations/chrono.rs index d52bc2dc..dada374b 100644 --- a/juniper/src/integrations/chrono.rs +++ b/juniper/src/integrations/chrono.rs @@ -210,7 +210,7 @@ mod integration_test { fn test_serialization() { struct Root; - #[crate::impl_object_internal] + #[crate::object_internal] impl Root { fn exampleNaiveDate() -> NaiveDate { NaiveDate::from_ymd(2015, 3, 14) diff --git a/juniper/src/lib.rs b/juniper/src/lib.rs index 9841e3ce..1a2943d4 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -109,14 +109,13 @@ extern crate uuid; // This allows users to just depend on juniper and get the derive // functionality automatically. pub use juniper_codegen::{ - impl_object, GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, ScalarValue, + object, GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, ScalarValue, }; // Internal macros are not exported, // but declared at the root to make them easier to use. #[allow(unused_imports)] use juniper_codegen::{ - impl_object_internal, GraphQLEnumInternal, GraphQLInputObjectInternal, - GraphQLScalarValueInternal, + object_internal, GraphQLEnumInternal, GraphQLInputObjectInternal, GraphQLScalarValueInternal, }; #[macro_use] diff --git a/juniper/src/macros/interface.rs b/juniper/src/macros/interface.rs index 0dfeed42..44d1c398 100644 --- a/juniper/src/macros/interface.rs +++ b/juniper/src/macros/interface.rs @@ -61,12 +61,12 @@ impl Character for Droid { fn id(&self) -> &str { &self.id } } -#[juniper::impl_object(Context = Database)] +#[juniper::object(Context = Database)] impl Human { fn id(&self) -> &str { &self.id } } -#[juniper::impl_object( +#[juniper::object( name = "Droid", Context = Database, )] diff --git a/juniper/src/macros/object.rs b/juniper/src/macros/object.rs index 02c27d31..7d6733e8 100644 --- a/juniper/src/macros/object.rs +++ b/juniper/src/macros/object.rs @@ -2,7 +2,7 @@ ## DEPRECATION WARNING The `graphql_object!` macro is deprecated and will be removed soon. -Use the new[impl_object](https://docs.rs/juniper/latest/juniper/macro.impl_object.html) macro instead. +Use the new[object](https://docs.rs/juniper/latest/juniper/macro.object.html) macro instead. Expose GraphQL objects diff --git a/juniper/src/macros/tests/args.rs b/juniper/src/macros/tests/args.rs index 9874249a..1abda753 100644 --- a/juniper/src/macros/tests/args.rs +++ b/juniper/src/macros/tests/args.rs @@ -26,7 +26,7 @@ struct Point { x: i32, } -#[crate::impl_object_internal] +#[crate::object_internal] impl Root { fn simple() -> i32 { 0 diff --git a/juniper/src/macros/tests/field.rs b/juniper/src/macros/tests/field.rs index d023a768..29b9e3b6 100644 --- a/juniper/src/macros/tests/field.rs +++ b/juniper/src/macros/tests/field.rs @@ -20,7 +20,7 @@ Syntax to validate: */ -#[crate::impl_object_internal( +#[crate::object_internal( interfaces = [&Interface], )] impl Root { diff --git a/juniper/src/macros/tests/impl_object.rs b/juniper/src/macros/tests/impl_object.rs index 72ae6ef5..81427cd7 100644 --- a/juniper/src/macros/tests/impl_object.rs +++ b/juniper/src/macros/tests/impl_object.rs @@ -12,7 +12,7 @@ struct WithLifetime<'a> { value: &'a str, } -#[crate::impl_object_internal(Context=Context)] +#[crate::object_internal(Context=Context)] impl<'a> WithLifetime<'a> { fn value(&'a self) -> &'a str { self.value @@ -21,7 +21,7 @@ impl<'a> WithLifetime<'a> { struct WithContext; -#[crate::impl_object_internal(Context=Context)] +#[crate::object_internal(Context=Context)] impl WithContext { fn ctx(ctx: &Context) -> bool { ctx.flag1 @@ -33,7 +33,7 @@ struct Query { b: bool, } -#[crate::impl_object_internal( +#[crate::object_internal( scalar = crate::DefaultScalarValue, name = "Query", context = Context, @@ -106,7 +106,7 @@ impl<'a> Query { #[derive(Default)] struct Mutation; -#[crate::impl_object_internal(context = Context)] +#[crate::object_internal(context = Context)] impl Mutation { fn empty() -> bool { true @@ -114,7 +114,7 @@ impl Mutation { } #[test] -fn impl_object_introspect() { +fn object_introspect() { let res = util::run_info_query::("Query"); assert_eq!( res, @@ -222,7 +222,7 @@ fn impl_object_introspect() { } #[test] -fn impl_object_query() { +fn object_query() { let doc = r#" query { withSelf diff --git a/juniper/src/macros/tests/interface.rs b/juniper/src/macros/tests/interface.rs index c09a09f5..3d083d16 100644 --- a/juniper/src/macros/tests/interface.rs +++ b/juniper/src/macros/tests/interface.rs @@ -42,7 +42,7 @@ struct ResolversWithTrailingComma; struct Root; -#[crate::impl_object_internal] +#[crate::object_internal] impl Concrete { fn simple() -> i32 { 0 @@ -111,7 +111,7 @@ graphql_interface!(ResolversWithTrailingComma: () |&self| { field simple() -> i32 { 0 } }); -#[crate::impl_object_internal] +#[crate::object_internal] impl<'a> Root { fn custom_name() -> CustomName { CustomName {} diff --git a/juniper/src/macros/tests/scalar.rs b/juniper/src/macros/tests/scalar.rs index 48a9af2e..febdb1bc 100644 --- a/juniper/src/macros/tests/scalar.rs +++ b/juniper/src/macros/tests/scalar.rs @@ -78,7 +78,7 @@ graphql_scalar!(ScalarDescription { } }); -#[crate::impl_object_internal] +#[crate::object_internal] impl Root { fn default_name() -> DefaultName { DefaultName(0) diff --git a/juniper/src/macros/tests/union.rs b/juniper/src/macros/tests/union.rs index 92a0ec97..fdc8c905 100644 --- a/juniper/src/macros/tests/union.rs +++ b/juniper/src/macros/tests/union.rs @@ -46,7 +46,7 @@ enum ResolversWithTrailingComma { struct Root; -#[crate::impl_object_internal] +#[crate::object_internal] impl Concrete { fn simple() -> i32 { 123 @@ -99,7 +99,7 @@ graphql_union!(ResolversWithTrailingComma: () |&self| { description: "A description" }); -#[crate::impl_object_internal] +#[crate::object_internal] impl<'a> Root { fn custom_name() -> CustomName { CustomName::Concrete(Concrete) diff --git a/juniper/src/parser/tests/value.rs b/juniper/src/parser/tests/value.rs index 8606b800..a59c3825 100644 --- a/juniper/src/parser/tests/value.rs +++ b/juniper/src/parser/tests/value.rs @@ -31,7 +31,7 @@ struct Foo { struct Query; -#[crate::impl_object_internal(Scalar = S)] +#[crate::object_internal(Scalar = S)] impl<'a, S> Query where S: crate::ScalarValue + 'a, diff --git a/juniper/src/schema/schema.rs b/juniper/src/schema/schema.rs index 1ff43a13..5ca0fdd6 100644 --- a/juniper/src/schema/schema.rs +++ b/juniper/src/schema/schema.rs @@ -73,7 +73,7 @@ where } } -#[crate::impl_object_internal( +#[crate::object_internal( name = "__Schema" Context = SchemaType<'a, S>, Scalar = S, @@ -111,7 +111,7 @@ where } } -#[crate::impl_object_internal( +#[crate::object_internal( name = "__Type" Context = SchemaType<'a, S>, Scalar = S, @@ -242,7 +242,7 @@ where } } -#[crate::impl_object_internal( +#[crate::object_internal( name = "__Field", Context = SchemaType<'a, S>, Scalar = S, @@ -279,7 +279,7 @@ where } } -#[crate::impl_object_internal( +#[crate::object_internal( name = "__InputValue", Context = SchemaType<'a, S>, Scalar = S, @@ -306,7 +306,7 @@ where } } -#[crate::impl_object_internal( +#[crate::object_internal( name = "__EnumValue", Scalar = S, )] @@ -331,7 +331,7 @@ where } } -#[crate::impl_object_internal( +#[crate::object_internal( name = "__Directive", Context = SchemaType<'a, S>, Scalar = S, diff --git a/juniper/src/tests/schema.rs b/juniper/src/tests/schema.rs index d88faa82..a39abd59 100644 --- a/juniper/src/tests/schema.rs +++ b/juniper/src/tests/schema.rs @@ -29,7 +29,7 @@ graphql_interface!(<'a> &'a Character: Database as "Character" |&self| { } }); -#[crate::impl_object_internal( +#[crate::object_internal( Context = Database, Scalar = crate::DefaultScalarValue, interfaces = [&dyn Character], @@ -62,7 +62,7 @@ impl<'a> &'a Human { } } -#[crate::impl_object_internal( +#[crate::object_internal( Context = Database, Scalar = crate::DefaultScalarValue, interfaces = [&dyn Character], @@ -95,7 +95,7 @@ impl<'a> &'a Droid { } } -#[crate::impl_object_internal( +#[crate::object_internal( name = "Query", Context = Database, Scalar = crate::DefaultScalarValue, diff --git a/juniper_codegen/src/impl_object.rs b/juniper_codegen/src/impl_object.rs index baff884b..4479d89a 100644 --- a/juniper_codegen/src/impl_object.rs +++ b/juniper_codegen/src/impl_object.rs @@ -2,8 +2,8 @@ use crate::util; use proc_macro::TokenStream; use quote::quote; -/// Generate code for the juniper::impl_object macro. -pub fn build_impl_object(args: TokenStream, body: TokenStream, is_internal: bool) -> TokenStream { +/// Generate code for the juniper::object macro. +pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) -> TokenStream { let impl_attrs = match syn::parse::(args) { Ok(attrs) => attrs, Err(e) => { @@ -62,11 +62,11 @@ pub fn build_impl_object(args: TokenStream, body: TokenStream, is_internal: bool .ident .to_string(), _ => { - panic!("Could not determine a name for the object type: specify one with #[juniper::impl_object(name = \"SomeName\")"); + panic!("Could not determine a name for the object type: specify one with #[juniper::object(name = \"SomeName\")"); } }, _ => { - panic!("Could not determine a name for the object type: specify one with #[juniper::impl_object(name = \"SomeName\")"); + panic!("Could not determine a name for the object type: specify one with #[juniper::object(name = \"SomeName\")"); } }, }; diff --git a/juniper_codegen/src/lib.rs b/juniper_codegen/src/lib.rs index 66e334bb..d9be341d 100644 --- a/juniper_codegen/src/lib.rs +++ b/juniper_codegen/src/lib.rs @@ -76,19 +76,19 @@ pub fn derive_scalar_value_internal(input: TokenStream) -> TokenStream { } /** -The `impl_object` proc macro is the primary way of defining GraphQL resolvers +The `object` proc macro is the primary way of defining GraphQL resolvers that can not be implemented with the GraphQLObject derive. It enables you to write GraphQL field resolvers for a type by declaring a regular Rust `impl` block. Under the hood, the procedural macro implements the GraphQLType trait. -`impl_object` comes with many features that allow customization of +`object` comes with many features that allow customization of your fields, all of which are detailed below. ### Getting Started -This simple example will show you the most basic use of `impl_object`. +This simple example will show you the most basic use of `object`. More advanced use cases are introduced step by step. ``` @@ -96,7 +96,7 @@ More advanced use cases are introduced step by step. struct Query; // We prefix the impl Block with the procedural macro. -#[juniper::impl_object] +#[juniper::object] impl Query { // A **warning**: only GraphQL fields can be specified in this impl block. @@ -110,7 +110,7 @@ impl Query { // - basic scalar types like bool, &str, String, i32, f64 // - GraphQL compatible wrappers like Option<_>, Vec<_>. // - types which use the `#derive[juniper::GraphQLObject]` - // - `impl_object` structs. + // - `object` structs. // // An important note regarding naming: // By default, field names will be converted to camel case. @@ -147,7 +147,7 @@ impl Person { } } -#[juniper::impl_object] +#[juniper::object] impl Person { fn first_name(&self) -> &str { &self.first_name @@ -187,7 +187,7 @@ impl juniper::Context for Context {} struct Query; -#[juniper::impl_object( +#[juniper::object( // Here we specify the context type for this object. Context = Context, )] @@ -217,7 +217,7 @@ struct InternalQuery; // Doc comments can be used to specify graphql documentation. /// GRAPHQL DOCUMENTATION. /// More info for GraphQL users.... -#[juniper::impl_object( +#[juniper::object( // You can rename the type for GraphQL by specifying the name here. name = "Query", // You can also specify a description here. @@ -280,7 +280,7 @@ struct WithLifetime<'a> { value: &'a str, } -#[juniper::impl_object] +#[juniper::object] impl<'a> WithLifetime<'a> { fn value(&self) -> &str { self.value @@ -301,7 +301,7 @@ You can easily specify a custom scalar though. struct Query; -#[juniper::impl_object( +#[juniper::object( Scalar = MyCustomScalar, )] impl Query { @@ -311,15 +311,15 @@ impl Query { */ #[proc_macro_attribute] -pub fn impl_object(args: TokenStream, input: TokenStream) -> TokenStream { - let gen = impl_object::build_impl_object(args, input, false); +pub fn object(args: TokenStream, input: TokenStream) -> TokenStream { + let gen = impl_object::build_object(args, input, false); gen.into() } /// A proc macro for defining a GraphQL object. #[doc(hidden)] #[proc_macro_attribute] -pub fn impl_object_internal(args: TokenStream, input: TokenStream) -> TokenStream { - let gen = impl_object::build_impl_object(args, input, true); +pub fn object_internal(args: TokenStream, input: TokenStream) -> TokenStream { + let gen = impl_object::build_object(args, input, true); gen.into() } diff --git a/juniper_codegen/src/util.rs b/juniper_codegen/src/util.rs index 7c8f8632..e1eb7cf8 100644 --- a/juniper_codegen/src/util.rs +++ b/juniper_codegen/src/util.rs @@ -508,7 +508,7 @@ pub struct FieldAttributes { pub deprecation: Option, // Only relevant for GraphQLObject derive. pub skip: bool, - /// Only relevant for impl_object macro. + /// Only relevant for object macro. pub arguments: HashMap, } diff --git a/juniper_iron/src/lib.rs b/juniper_iron/src/lib.rs index ea546a77..f97f6a5e 100644 --- a/juniper_iron/src/lib.rs +++ b/juniper_iron/src/lib.rs @@ -37,7 +37,7 @@ use juniper::{Context, EmptyMutation}; # struct QueryRoot; # struct Database { users: HashMap } # -# #[juniper::impl_object( Context = Database )] +# #[juniper::object( Context = Database )] # impl User { # fn id(&self) -> FieldResult<&String> { # Ok(&self.id) @@ -54,7 +54,7 @@ use juniper::{Context, EmptyMutation}; # } # } # -# #[juniper::impl_object( Context = Database )] +# #[juniper::object( Context = Database )] # impl QueryRoot { # fn user(context: &Database, id: String) -> FieldResult> { # Ok(executor.context().users.get(&id)) diff --git a/juniper_warp/src/lib.rs b/juniper_warp/src/lib.rs index 9a458d78..3c1d442a 100644 --- a/juniper_warp/src/lib.rs +++ b/juniper_warp/src/lib.rs @@ -134,7 +134,7 @@ where /// /// struct QueryRoot; /// -/// #[juniper::impl_object( +/// #[juniper::object( /// Context = ExampleContext /// )] /// impl QueryRoot {