From ce3cf45ca9896cddca7f860d2031d6e7b501cd45 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Sat, 16 Nov 2019 02:43:39 +0100 Subject: [PATCH] Rename `object` proc macro to `graphql_object` --- docs/book/content/advanced/introspection.md | 2 +- .../content/advanced/non_struct_objects.md | 2 +- .../content/advanced/objects_and_generics.md | 4 +-- docs/book/content/quickstart.md | 6 ++--- .../content/schema/schemas_and_mutations.md | 4 +-- docs/book/content/servers/iron.md | 4 +-- docs/book/content/types/input_objects.md | 4 +-- .../content/types/objects/complex_fields.md | 8 +++--- .../content/types/objects/error_handling.md | 4 +-- .../content/types/objects/using_contexts.md | 2 +- examples/warp_async/src/main.rs | 4 +-- integration_tests/async_await/src/main.rs | 6 ++--- .../src/codegen/derive_object.rs | 2 +- .../codegen/derive_object_with_raw_idents.rs | 2 +- .../src/codegen/scalar_value_transparent.rs | 2 +- .../juniper_tests/src/custom_scalar.rs | 2 +- .../juniper_tests/src/issue_371.rs | 27 ++++++++++++------- .../juniper_tests/src/issue_398.rs | 6 ++--- juniper/CHANGELOG.md | 2 ++ juniper/src/executor_tests/async_await/mod.rs | 6 ++--- juniper/src/executor_tests/directives.rs | 2 +- juniper/src/executor_tests/enums.rs | 2 +- juniper/src/executor_tests/executor.rs | 22 +++++++-------- .../src/executor_tests/interfaces_unions.rs | 12 ++++----- .../src/executor_tests/introspection/enums.rs | 2 +- .../introspection/input_object.rs | 2 +- .../src/executor_tests/introspection/mod.rs | 2 +- juniper/src/executor_tests/variables.rs | 2 +- juniper/src/integrations/chrono.rs | 2 +- juniper/src/lib.rs | 7 ++--- juniper/src/macros/interface.rs | 4 +-- juniper/src/macros/tests/args.rs | 2 +- juniper/src/macros/tests/field.rs | 2 +- juniper/src/macros/tests/impl_object.rs | 8 +++--- juniper/src/macros/tests/interface.rs | 4 +-- juniper/src/macros/tests/object.rs | 2 +- juniper/src/macros/tests/scalar.rs | 2 +- juniper/src/macros/tests/union.rs | 4 +-- juniper/src/parser/tests/document.rs | 2 +- juniper/src/parser/tests/value.rs | 2 +- juniper/src/schema/schema.rs | 12 ++++----- juniper/src/tests/schema.rs | 6 ++--- juniper_benchmarks/src/lib.rs | 8 +++--- juniper_codegen/src/impl_object.rs | 6 ++--- juniper_codegen/src/lib.rs | 18 ++++++------- juniper_iron/src/lib.rs | 4 +-- juniper_warp/src/lib.rs | 2 +- 47 files changed, 126 insertions(+), 116 deletions(-) diff --git a/docs/book/content/advanced/introspection.md b/docs/book/content/advanced/introspection.md index a8675b03..34d1bf03 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::object( +#[juniper::graphql_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 bb23c28a..fc6a2dcc 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::object] +#[juniper::graphql_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 87b98437..b0cb406c 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::object( +#[juniper::graphql_object( name = "UserResult", )] impl MutationResult { @@ -38,7 +38,7 @@ impl MutationResult { } } -#[juniper::object( +#[juniper::graphql_object( name = "ForumPostResult", )] impl MutationResult { diff --git a/docs/book/content/quickstart.md b/docs/book/content/quickstart.md index 21917716..8537cc60 100644 --- a/docs/book/content/quickstart.md +++ b/docs/book/content/quickstart.md @@ -74,7 +74,7 @@ impl juniper::Context for Context {} struct Query; -#[juniper::object( +#[juniper::graphql_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::object( +#[juniper::graphql_object( Context = Context, )] impl Mutation { @@ -156,7 +156,7 @@ impl juniper::Context for Ctx {} struct Query; -#[juniper::object( +#[juniper::graphql_object( Context = Ctx, )] impl Query { diff --git a/docs/book/content/schema/schemas_and_mutations.md b/docs/book/content/schema/schemas_and_mutations.md index 543bc899..b3ba9a74 100644 --- a/docs/book/content/schema/schemas_and_mutations.md +++ b/docs/book/content/schema/schemas_and_mutations.md @@ -27,7 +27,7 @@ object in Juniper, most commonly using the `object` proc macro: # #[derive(juniper::GraphQLObject)] struct User { name: String } struct Root; -#[juniper::object] +#[juniper::graphql_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::object] +#[juniper::graphql_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 da76ba75..7077b9e1 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::object] +#[juniper::graphql_object] impl Root { fn foo() -> String { "Bar".to_owned() @@ -99,7 +99,7 @@ fn context_factory(req: &mut Request) -> IronResult { struct Root; -#[juniper::object( +#[juniper::graphql_object( Context = Context, )] impl Root { diff --git a/docs/book/content/types/input_objects.md b/docs/book/content/types/input_objects.md index 0d5aa45b..b60eef4a 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::object] +#[juniper::graphql_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::object] +#[juniper::graphql_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 902b442e..7ffd1694 100644 --- a/docs/book/content/types/objects/complex_fields.md +++ b/docs/book/content/types/objects/complex_fields.md @@ -14,7 +14,7 @@ struct Person { age: i32, } -#[juniper::object] +#[juniper::graphql_object] impl Person { fn name(&self) -> &str { self.name.as_str() @@ -43,7 +43,7 @@ struct House { inhabitants: Vec, } -#[juniper::object] +#[juniper::graphql_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 { } /// Doc comments are used as descriptions for GraphQL. -#[juniper::object( +#[juniper::graphql_object( // With this attribtue you can change the public GraphQL name of the type. name = "PersonObject", // You can also specify a description here, which will overwrite @@ -125,7 +125,7 @@ This will become better once the [Rust RFC 2565](https://github.com/rust-lang/ru struct Person {} -#[juniper::object] +#[juniper::graphql_object] impl Person { #[graphql( arguments( diff --git a/docs/book/content/types/objects/error_handling.md b/docs/book/content/types/objects/error_handling.md index fe136fba..21de32e8 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::object] +#[juniper::graphql_object] impl Example { fn contents() -> FieldResult { let mut file = File::open(&self.filename)?; @@ -143,7 +143,7 @@ struct Example { whatever: Option, } -#[juniper::object] +#[juniper::graphql_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 676dc6a0..1233ec5b 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::object( +#[juniper::graphql_object( Context = Database, )] impl User { diff --git a/examples/warp_async/src/main.rs b/examples/warp_async/src/main.rs index 9bbe3884..e81a36dd 100644 --- a/examples/warp_async/src/main.rs +++ b/examples/warp_async/src/main.rs @@ -24,7 +24,7 @@ struct User { name: String, } -#[juniper::object(Context = Context)] +#[juniper::graphql_object(Context = Context)] impl User { fn id(&self) -> i32 { self.id @@ -45,7 +45,7 @@ impl User { struct Query; -#[juniper::object(Context = Context)] +#[juniper::graphql_object(Context = Context)] impl Query { async fn users() -> Vec { vec![ diff --git a/integration_tests/async_await/src/main.rs b/integration_tests/async_await/src/main.rs index feb68bca..ae973c1a 100644 --- a/integration_tests/async_await/src/main.rs +++ b/integration_tests/async_await/src/main.rs @@ -13,7 +13,7 @@ struct User { kind: UserKind, } -#[juniper::object] +#[juniper::graphql_object] impl User { async fn name(&self) -> &str { &self.name @@ -43,7 +43,7 @@ impl User { struct Query; -#[juniper::object] +#[juniper::graphql_object] impl Query { fn field_sync(&self) -> &'static str { "field_sync" @@ -70,7 +70,7 @@ impl Query { struct Mutation; -#[juniper::object] +#[juniper::graphql_object] impl Mutation {} fn run(f: impl std::future::Future) -> O { diff --git a/integration_tests/juniper_tests/src/codegen/derive_object.rs b/integration_tests/juniper_tests/src/codegen/derive_object.rs index d53d8fa3..049eddb1 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_object.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_object.rs @@ -79,7 +79,7 @@ struct WithCustomContext { a: bool, } -#[juniper::object] +#[juniper::graphql_object] impl Query { fn obj() -> Obj { Obj { diff --git a/integration_tests/juniper_tests/src/codegen/derive_object_with_raw_idents.rs b/integration_tests/juniper_tests/src/codegen/derive_object_with_raw_idents.rs index 93549ac8..ddd84eaf 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_object_with_raw_idents.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_object_with_raw_idents.rs @@ -11,7 +11,7 @@ use juniper::{ pub struct Query; -#[juniper::object] +#[juniper::graphql_object] impl Query { fn r#type(r#fn: MyInputType) -> Vec { unimplemented!() diff --git a/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs b/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs index e65ea8bd..6f52e5b6 100644 --- a/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs +++ b/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs @@ -22,7 +22,7 @@ struct User { struct User2; -#[juniper::object] +#[juniper::graphql_object] impl User2 { fn id(&self) -> UserId { UserId("id".to_string()) diff --git a/integration_tests/juniper_tests/src/custom_scalar.rs b/integration_tests/juniper_tests/src/custom_scalar.rs index daf61bb4..3fb7293e 100644 --- a/integration_tests/juniper_tests/src/custom_scalar.rs +++ b/integration_tests/juniper_tests/src/custom_scalar.rs @@ -160,7 +160,7 @@ juniper::graphql_scalar!(i64 as "Long" where Scalar = MyScalarValue { struct TestType; -#[juniper::object( +#[juniper::graphql_object( Scalar = MyScalarValue )] impl TestType { diff --git a/integration_tests/juniper_tests/src/issue_371.rs b/integration_tests/juniper_tests/src/issue_371.rs index 53c8cf8a..d9fe27a4 100644 --- a/integration_tests/juniper_tests/src/issue_371.rs +++ b/integration_tests/juniper_tests/src/issue_371.rs @@ -7,37 +7,44 @@ impl juniper::Context for Context {} pub struct Query; -graphql_object!(Query: Context |&self| { - field users(&executor) -> Vec { +#[graphql_object( + Context = Context +)] +impl Query { + fn users(exec: &Executor) -> Vec { let lh = executor.look_ahead(); assert_eq!(lh.field_name(), "users"); vec![User] } - field countries(&executor) -> Vec { + fn countries(exec: &Executor) -> Vec { let lh = executor.look_ahead(); assert_eq!(lh.field_name(), "countries"); vec![Country] } -}); +} #[derive(Clone)] pub struct User; -graphql_object!(User: Context |&self| { - field id() -> i32 { +#[graphql_object( + Context = Context +)] +impl User { + fn id() -> i32 { 1 } -}); +} #[derive(Clone)] pub struct Country; -graphql_object!(Country: Context |&self| { - field id() -> i32 { +#[graphql_object] +impl Country { + fn id() -> i32 { 2 } -}); +} type Schema = juniper::RootNode<'static, Query, EmptyMutation>; diff --git a/integration_tests/juniper_tests/src/issue_398.rs b/integration_tests/juniper_tests/src/issue_398.rs index 8c36d179..7e7a71fd 100644 --- a/integration_tests/juniper_tests/src/issue_398.rs +++ b/integration_tests/juniper_tests/src/issue_398.rs @@ -3,7 +3,7 @@ use juniper::*; struct Query; -#[juniper::object] +#[juniper::graphql_object] impl Query { fn users(executor: &Executor) -> Vec { // This doesn't cause a panic @@ -19,7 +19,7 @@ struct User { country: Country, } -#[juniper::object] +#[juniper::graphql_object] impl User { fn country(&self, executor: &Executor) -> &Country { // This panics! @@ -33,7 +33,7 @@ struct Country { id: i32, } -#[juniper::object] +#[juniper::graphql_object] impl Country { fn id(&self) -> i32 { self.id diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index 70ba3183..55e49418 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -6,6 +6,8 @@ ## Breaking Changes +- remove old `graphql_object!` macro, rename `object` proc macro to `graphql_object` + - Remove deprecated `ScalarValue` custom derive (renamed to GraphQLScalarValue) - `graphql_union!` macro removed, replaced by `#[graphql_union]` proc macro diff --git a/juniper/src/executor_tests/async_await/mod.rs b/juniper/src/executor_tests/async_await/mod.rs index 45c25540..0c4b36b8 100644 --- a/juniper/src/executor_tests/async_await/mod.rs +++ b/juniper/src/executor_tests/async_await/mod.rs @@ -13,7 +13,7 @@ struct User { kind: UserKind, } -#[crate::object_internal] +#[crate::graphql_object_internal] impl User { async fn name(&self) -> &str { &self.name @@ -43,7 +43,7 @@ impl User { struct Query; -#[crate::object_internal] +#[crate::graphql_object_internal] impl Query { fn field_sync(&self) -> &'static str { "field_sync" @@ -70,7 +70,7 @@ impl Query { struct Mutation; -#[crate::object_internal] +#[crate::graphql_object_internal] impl Mutation {} fn run(f: impl std::future::Future) -> O { diff --git a/juniper/src/executor_tests/directives.rs b/juniper/src/executor_tests/directives.rs index 124ac38f..59cc116a 100644 --- a/juniper/src/executor_tests/directives.rs +++ b/juniper/src/executor_tests/directives.rs @@ -7,7 +7,7 @@ use crate::{ struct TestType; -#[crate::object_internal] +#[crate::graphql_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 2a331ae3..a4f8ae4b 100644 --- a/juniper/src/executor_tests/enums.rs +++ b/juniper/src/executor_tests/enums.rs @@ -19,7 +19,7 @@ enum Color { } struct TestType; -#[crate::object_internal] +#[crate::graphql_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 701ed387..5dd443a0 100644 --- a/juniper/src/executor_tests/executor.rs +++ b/juniper/src/executor_tests/executor.rs @@ -6,7 +6,7 @@ mod field_execution { struct DataType; struct DeepDataType; - #[crate::object_internal] + #[crate::graphql_object_internal] impl DataType { fn a() -> &str { "Apple" @@ -36,7 +36,7 @@ mod field_execution { } } - #[crate::object_internal] + #[crate::graphql_object_internal] impl DeepDataType { fn a() -> &str { "Already Been Done" @@ -159,7 +159,7 @@ mod merge_parallel_fragments { struct Type; - #[crate::object_internal] + #[crate::graphql_object_internal] impl Type { fn a() -> &str { "Apple" @@ -241,7 +241,7 @@ mod merge_parallel_inline_fragments { struct Type; struct Other; - #[crate::object_internal] + #[crate::graphql_object_internal] impl Type { fn a() -> &str { "Apple" @@ -260,7 +260,7 @@ mod merge_parallel_inline_fragments { } } - #[crate::object_internal] + #[crate::graphql_object_internal] impl Other { fn a() -> &str { "Apple" @@ -390,7 +390,7 @@ mod threads_context_correctly { impl Context for TestContext {} - #[crate::object_internal( + #[crate::graphql_object_internal( Context = TestContext, )] impl Schema { @@ -458,7 +458,7 @@ mod dynamic_context_switching { struct ItemRef; - #[crate::object_internal(Context = OuterContext)] + #[crate::graphql_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)) @@ -488,7 +488,7 @@ mod dynamic_context_switching { } } - #[crate::object_internal(Context = InnerContext)] + #[crate::graphql_object_internal(Context = InnerContext)] impl ItemRef { fn value(context: &InnerContext) -> String { context.value.clone() @@ -799,7 +799,7 @@ mod propagates_errors_to_nullable_fields { } } - #[crate::object_internal] + #[crate::graphql_object_internal] impl Schema { fn inner() -> Inner { Inner @@ -812,7 +812,7 @@ mod propagates_errors_to_nullable_fields { } } - #[crate::object_internal] + #[crate::graphql_object_internal] impl Inner { fn nullable_field() -> Option { Some(Inner) @@ -1065,7 +1065,7 @@ mod named_operations { struct Schema; - #[crate::object_internal] + #[crate::graphql_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 e7cd87cf..6f43d559 100644 --- a/juniper/src/executor_tests/interfaces_unions.rs +++ b/juniper/src/executor_tests/interfaces_unions.rs @@ -35,7 +35,7 @@ mod interface { } } - #[crate::object_internal( + #[crate::graphql_object_internal( interfaces = [&dyn Pet] )] impl Dog { @@ -61,7 +61,7 @@ mod interface { } } - #[crate::object_internal( + #[crate::graphql_object_internal( interfaces = [&dyn Pet] )] impl Cat { @@ -77,7 +77,7 @@ mod interface { pets: Vec>, } - #[crate::object_internal] + #[crate::graphql_object_internal] impl Schema { fn pets(&self) -> Vec<&dyn Pet> { self.pets.iter().map(|p| p.as_ref()).collect() @@ -187,7 +187,7 @@ mod union { } } - #[crate::object_internal] + #[crate::graphql_object_internal] impl Dog { fn name(&self) -> &str { &self.name @@ -208,7 +208,7 @@ mod union { } } - #[crate::object_internal] + #[crate::graphql_object_internal] impl Cat { fn name(&self) -> &str { &self.name @@ -222,7 +222,7 @@ mod union { pets: Vec>, } - #[crate::object_internal] + #[crate::graphql_object_internal] impl Schema { fn pets(&self) -> Vec<&dyn 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 639ee536..c7c57946 100644 --- a/juniper/src/executor_tests/introspection/enums.rs +++ b/juniper/src/executor_tests/introspection/enums.rs @@ -66,7 +66,7 @@ enum EnumDeprecation { struct Root; -#[crate::object_internal] +#[crate::graphql_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 02d6f2b3..23b01ce4 100644 --- a/juniper/src/executor_tests/introspection/input_object.rs +++ b/juniper/src/executor_tests/introspection/input_object.rs @@ -81,7 +81,7 @@ struct FieldWithDefaults { field_two: i32, } -#[crate::object_internal] +#[crate::graphql_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 00fa0140..4775a535 100644 --- a/juniper/src/executor_tests/introspection/mod.rs +++ b/juniper/src/executor_tests/introspection/mod.rs @@ -54,7 +54,7 @@ graphql_interface!(Interface: () as "SampleInterface" |&self| { }); /// The root query object in the schema -#[crate::object_internal( +#[crate::graphql_object_internal( interfaces = [&Interface] Scalar = crate::DefaultScalarValue, )] diff --git a/juniper/src/executor_tests/variables.rs b/juniper/src/executor_tests/variables.rs index cce48291..6fbbc6b5 100644 --- a/juniper/src/executor_tests/variables.rs +++ b/juniper/src/executor_tests/variables.rs @@ -64,7 +64,7 @@ struct InputWithDefaults { a: i32, } -#[crate::object_internal] +#[crate::graphql_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 08c54d6f..4f1745cd 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::object_internal] + #[crate::graphql_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 9062c2a7..be21a809 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -110,14 +110,15 @@ extern crate uuid; // This allows users to just depend on juniper and get the derive // functionality automatically. pub use juniper_codegen::{ - graphql_union, object, GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, + graphql_object, graphql_union, GraphQLEnum, GraphQLInputObject, GraphQLObject, + GraphQLScalarValue, }; // Internal macros are not exported, // but declared at the root to make them easier to use. #[allow(unused_imports)] use juniper_codegen::{ - graphql_union_internal, object_internal, GraphQLEnumInternal, GraphQLInputObjectInternal, - GraphQLScalarValueInternal, + graphql_object_internal, graphql_union_internal, GraphQLEnumInternal, + GraphQLInputObjectInternal, GraphQLScalarValueInternal, }; #[macro_use] diff --git a/juniper/src/macros/interface.rs b/juniper/src/macros/interface.rs index 1bbe4ead..e9b4a8b9 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::object(Context = Database)] +#[juniper::graphql_object(Context = Database)] impl Human { fn id(&self) -> &str { &self.id } } -#[juniper::object( +#[juniper::graphql_object( name = "Droid", Context = Database, )] diff --git a/juniper/src/macros/tests/args.rs b/juniper/src/macros/tests/args.rs index 24c66f62..1d251460 100644 --- a/juniper/src/macros/tests/args.rs +++ b/juniper/src/macros/tests/args.rs @@ -28,7 +28,7 @@ struct Point { x: i32, } -#[crate::object_internal] +#[crate::graphql_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 1b9c4268..a13d9b1d 100644 --- a/juniper/src/macros/tests/field.rs +++ b/juniper/src/macros/tests/field.rs @@ -22,7 +22,7 @@ Syntax to validate: */ -#[crate::object_internal( +#[crate::graphql_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 653864fa..0c07f057 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::object_internal(Context=Context)] +#[crate::graphql_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::object_internal(Context=Context)] +#[crate::graphql_object_internal(Context=Context)] impl WithContext { fn ctx(ctx: &Context) -> bool { ctx.flag1 @@ -33,7 +33,7 @@ struct Query { b: bool, } -#[crate::object_internal( +#[crate::graphql_object_internal( scalar = crate::DefaultScalarValue, name = "Query", context = Context, @@ -115,7 +115,7 @@ impl<'a> Query { #[derive(Default)] struct Mutation; -#[crate::object_internal(context = Context)] +#[crate::graphql_object_internal(context = Context)] impl Mutation { fn empty() -> bool { true diff --git a/juniper/src/macros/tests/interface.rs b/juniper/src/macros/tests/interface.rs index 76fb40d0..608fddbd 100644 --- a/juniper/src/macros/tests/interface.rs +++ b/juniper/src/macros/tests/interface.rs @@ -44,7 +44,7 @@ struct ResolversWithTrailingComma; struct Root; -#[crate::object_internal] +#[crate::graphql_object_internal] impl Concrete { fn simple() -> i32 { 0 @@ -113,7 +113,7 @@ graphql_interface!(ResolversWithTrailingComma: () |&self| { field simple() -> i32 { 0 } }); -#[crate::object_internal( +#[crate::graphql_object_internal( // FIXME: make async work noasync )] diff --git a/juniper/src/macros/tests/object.rs b/juniper/src/macros/tests/object.rs index 85738114..ce45c48c 100644 --- a/juniper/src/macros/tests/object.rs +++ b/juniper/src/macros/tests/object.rs @@ -1,5 +1,5 @@ // TODO: make sure proc macro tests cover all -// variants of the below +// variants of the below /* use std::marker::PhantomData; diff --git a/juniper/src/macros/tests/scalar.rs b/juniper/src/macros/tests/scalar.rs index 7e879712..e64bda9e 100644 --- a/juniper/src/macros/tests/scalar.rs +++ b/juniper/src/macros/tests/scalar.rs @@ -80,7 +80,7 @@ graphql_scalar!(ScalarDescription { } }); -#[crate::object_internal] +#[crate::graphql_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 6e9f2972..ab54cf46 100644 --- a/juniper/src/macros/tests/union.rs +++ b/juniper/src/macros/tests/union.rs @@ -38,7 +38,7 @@ enum DescriptionFirst { struct Root; -#[crate::object_internal] +#[crate::graphql_object_internal] impl Concrete { fn simple() -> i32 { 123 @@ -90,7 +90,7 @@ impl DescriptionFirst { } // FIXME: make async work -#[crate::object_internal(noasync)] +#[crate::graphql_object_internal(noasync)] impl<'a> Root { fn custom_name() -> CustomName { CustomName::Concrete(Concrete) diff --git a/juniper/src/parser/tests/document.rs b/juniper/src/parser/tests/document.rs index 24f99963..6ad46b75 100644 --- a/juniper/src/parser/tests/document.rs +++ b/juniper/src/parser/tests/document.rs @@ -149,7 +149,7 @@ fn errors() { fn issue_427_panic_is_not_expected() { struct QueryWithoutFloat; - #[crate::object_internal] + #[crate::graphql_object_internal] impl QueryWithoutFloat { fn echo(value: String) -> String { value diff --git a/juniper/src/parser/tests/value.rs b/juniper/src/parser/tests/value.rs index f0c34ed0..c8aba174 100644 --- a/juniper/src/parser/tests/value.rs +++ b/juniper/src/parser/tests/value.rs @@ -36,7 +36,7 @@ struct Foo { struct Query; -#[crate::object_internal(Scalar = S)] +#[crate::graphql_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 d658668d..b0c42664 100644 --- a/juniper/src/schema/schema.rs +++ b/juniper/src/schema/schema.rs @@ -106,7 +106,7 @@ where } } -#[crate::object_internal( +#[crate::graphql_object_internal( name = "__Schema" Context = SchemaType<'a, S>, Scalar = S, @@ -145,7 +145,7 @@ where } } -#[crate::object_internal( +#[crate::graphql_object_internal( name = "__Type" Context = SchemaType<'a, S>, Scalar = S, @@ -278,7 +278,7 @@ where } } -#[crate::object_internal( +#[crate::graphql_object_internal( name = "__Field", Context = SchemaType<'a, S>, Scalar = S, @@ -317,7 +317,7 @@ where } } -#[crate::object_internal( +#[crate::graphql_object_internal( name = "__InputValue", Context = SchemaType<'a, S>, Scalar = S, @@ -346,7 +346,7 @@ where } } -#[crate::object_internal( +#[crate::graphql_object_internal( name = "__EnumValue", Scalar = S, // FIXME: make this redundant. @@ -373,7 +373,7 @@ where } } -#[crate::object_internal( +#[crate::graphql_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 47eefeff..f088e609 100644 --- a/juniper/src/tests/schema.rs +++ b/juniper/src/tests/schema.rs @@ -33,7 +33,7 @@ graphql_interface!(<'a> &'a dyn Character: Database as "Character" |&self| { } }); -#[crate::object_internal( +#[crate::graphql_object_internal( Context = Database, Scalar = crate::DefaultScalarValue, interfaces = [&dyn Character], @@ -68,7 +68,7 @@ impl<'a> &'a dyn Human { } } -#[crate::object_internal( +#[crate::graphql_object_internal( Context = Database, Scalar = crate::DefaultScalarValue, interfaces = [&dyn Character], @@ -105,7 +105,7 @@ impl<'a> &'a dyn Droid { pub struct Query; -#[crate::object_internal( +#[crate::graphql_object_internal( Context = Database, Scalar = crate::DefaultScalarValue, // FIXME: make async work diff --git a/juniper_benchmarks/src/lib.rs b/juniper_benchmarks/src/lib.rs index 4a79da2f..6cdb7a51 100644 --- a/juniper_benchmarks/src/lib.rs +++ b/juniper_benchmarks/src/lib.rs @@ -1,5 +1,5 @@ use juniper::{ - object, DefaultScalarValue, ExecutionError, FieldError, GraphQLEnum, Value, Variables, + graphql_object, DefaultScalarValue, ExecutionError, FieldError, GraphQLEnum, Value, Variables, }; pub type QueryResult = Result< @@ -56,12 +56,12 @@ impl User { } } -#[object(Context = Context)] +#[graphql_object(Context = Context)] impl User {} pub struct Query; -#[object(Context = Context)] +#[graphql_object(Context = Context)] impl Query { fn user_sync_instant(id: i32) -> Result { Ok(User::new(id)) @@ -92,7 +92,7 @@ impl Query { pub struct Mutation; -#[object(Context = Context)] +#[graphql_object(Context = Context)] impl Mutation {} pub fn new_schema() -> juniper::RootNode<'static, Query, Mutation> { diff --git a/juniper_codegen/src/impl_object.rs b/juniper_codegen/src/impl_object.rs index 3613d36b..6df56909 100644 --- a/juniper_codegen/src/impl_object.rs +++ b/juniper_codegen/src/impl_object.rs @@ -2,7 +2,7 @@ use crate::util; use proc_macro::TokenStream; use quote::quote; -/// Generate code for the juniper::object macro. +/// Generate code for the juniper::graphql_object macro. pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) -> TokenStream { let impl_attrs = match syn::parse::(args) { Ok(attrs) => attrs, @@ -20,7 +20,7 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) -> let mut _impl = match item { syn::Item::Impl(_impl) => _impl, _ => { - panic!("#[juniper::object] can only be applied to impl blocks"); + panic!("#[juniper::graphql_object] can only be applied to impl blocks"); } }; @@ -47,7 +47,7 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) -> if let Some(ident) = util::name_of_type(&*_impl.self_ty) { ident.to_string() } else { - 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::graphql_object(name = \"SomeName\")"); } }; diff --git a/juniper_codegen/src/lib.rs b/juniper_codegen/src/lib.rs index f2036079..4d230436 100644 --- a/juniper_codegen/src/lib.rs +++ b/juniper_codegen/src/lib.rs @@ -135,7 +135,7 @@ More advanced use cases are introduced step by step. struct Query; // We prefix the impl Block with the procedural macro. -#[juniper::object] +#[juniper::graphql_object] impl Query { // A **warning**: only GraphQL fields can be specified in this impl block. @@ -186,7 +186,7 @@ impl Person { } } -#[juniper::object] +#[juniper::graphql_object] impl Person { fn first_name(&self) -> &str { &self.first_name @@ -226,7 +226,7 @@ impl juniper::Context for Context {} struct Query; -#[juniper::object( +#[juniper::graphql_object( // Here we specify the context type for this object. Context = Context, )] @@ -256,7 +256,7 @@ struct InternalQuery; // Doc comments can be used to specify graphql documentation. /// GRAPHQL DOCUMENTATION. /// More info for GraphQL users.... -#[juniper::object( +#[juniper::graphql_object( // You can rename the type for GraphQL by specifying the name here. name = "Query", // You can also specify a description here. @@ -319,7 +319,7 @@ struct WithLifetime<'a> { value: &'a str, } -#[juniper::object] +#[juniper::graphql_object] impl<'a> WithLifetime<'a> { fn value(&self) -> &str { self.value @@ -340,7 +340,7 @@ You can easily specify a custom scalar though. struct Query; -#[juniper::object( +#[juniper::graphql_object( Scalar = MyCustomScalar, )] impl Query { @@ -358,7 +358,7 @@ struct User { r#type: String, } -#[juniper::object] +#[juniper::graphql_object] impl User { fn r#type(&self) -> &str { &self.r#type @@ -368,7 +368,7 @@ impl User { */ #[proc_macro_attribute] -pub fn object(args: TokenStream, input: TokenStream) -> TokenStream { +pub fn graphql_object(args: TokenStream, input: TokenStream) -> TokenStream { let gen = impl_object::build_object(args, input, false); gen.into() } @@ -376,7 +376,7 @@ pub fn object(args: TokenStream, input: TokenStream) -> TokenStream { /// A proc macro for defining a GraphQL object. #[doc(hidden)] #[proc_macro_attribute] -pub fn object_internal(args: TokenStream, input: TokenStream) -> TokenStream { +pub fn graphql_object_internal(args: TokenStream, input: TokenStream) -> TokenStream { let gen = impl_object::build_object(args, input, true); gen.into() } diff --git a/juniper_iron/src/lib.rs b/juniper_iron/src/lib.rs index 39271106..a7802038 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::object( Context = Database )] +# #[juniper::graphql_object( Context = Database )] # impl User { # fn id(&self) -> FieldResult<&String> { # Ok(&self.id) @@ -54,7 +54,7 @@ use juniper::{Context, EmptyMutation}; # } # } # -# #[juniper::object( Context = Database )] +# #[juniper::graphql_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 a68cb5d8..936380de 100644 --- a/juniper_warp/src/lib.rs +++ b/juniper_warp/src/lib.rs @@ -169,7 +169,7 @@ where /// /// struct QueryRoot; /// -/// #[juniper::object( +/// #[juniper::graphql_object( /// Context = ExampleContext /// )] /// impl QueryRoot {