diff --git a/juniper/src/lib.rs b/juniper/src/lib.rs index 5b955218..9841e3ce 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -109,21 +109,14 @@ extern crate uuid; // This allows users to just depend on juniper and get the derive // functionality automatically. pub use juniper_codegen::{ - GraphQLEnum, - GraphQLInputObject, - GraphQLObject, - GraphQLScalarValue, - ScalarValue, - impl_object, + impl_object, GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, ScalarValue, }; -// Internal macros are not exported, +// 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, - GraphQLEnumInternal, - GraphQLInputObjectInternal, - impl_object_internal, }; #[macro_use] diff --git a/juniper/src/macros/object.rs b/juniper/src/macros/object.rs index 713f371f..02c27d31 100644 --- a/juniper/src/macros/object.rs +++ b/juniper/src/macros/object.rs @@ -1,7 +1,7 @@ /** ## DEPRECATION WARNING -The `graphql_object!` macro is deprecated and will be removed soon. +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. Expose GraphQL objects diff --git a/juniper/src/schema/schema.rs b/juniper/src/schema/schema.rs index deaa006b..1ff43a13 100644 --- a/juniper/src/schema/schema.rs +++ b/juniper/src/schema/schema.rs @@ -146,15 +146,13 @@ where fn fields(&self, include_deprecated: bool) -> Option>> { match *self { TypeType::Concrete(&MetaType::Interface(InterfaceMeta { ref fields, .. })) - | TypeType::Concrete(&MetaType::Object(ObjectMeta { ref fields, .. })) => { - Some( - fields - .iter() - .filter(|f| include_deprecated || !f.deprecation_status.is_deprecated()) - .filter(|f| !f.name.starts_with("__")) - .collect(), - ) - } + | TypeType::Concrete(&MetaType::Object(ObjectMeta { ref fields, .. })) => Some( + fields + .iter() + .filter(|f| include_deprecated || !f.deprecation_status.is_deprecated()) + .filter(|f| !f.name.starts_with("__")) + .collect(), + ), _ => None, } } @@ -233,14 +231,12 @@ where #[graphql(arguments(include_deprecated(default = false)))] fn enum_values(&self, include_deprecated: bool) -> Option> { match *self { - TypeType::Concrete(&MetaType::Enum(EnumMeta { ref values, .. })) => { - Some( - values - .iter() - .filter(|f| include_deprecated || !f.deprecation_status.is_deprecated()) - .collect(), - ) - } + TypeType::Concrete(&MetaType::Enum(EnumMeta { ref values, .. })) => Some( + values + .iter() + .filter(|f| include_deprecated || !f.deprecation_status.is_deprecated()) + .collect(), + ), _ => None, } } diff --git a/juniper_codegen/src/impl_object.rs b/juniper_codegen/src/impl_object.rs index 4e07cf52..baff884b 100644 --- a/juniper_codegen/src/impl_object.rs +++ b/juniper_codegen/src/impl_object.rs @@ -148,7 +148,7 @@ pub fn build_impl_object(args: TokenStream, body: TokenStream, is_internal: bool // Check for executor arguments. if util::type_is_identifier_ref(&captured.ty, "Executor") { resolve_parts.push(quote!(let #arg_ident = executor;)); - } + } // Make sure executor is specified as a reference. else if util::type_is_identifier(&captured.ty, "Executor") { panic!("Invalid executor argument: to access the Executor, you need to specify the type as a reference.\nDid you mean &Executor?"); @@ -160,16 +160,19 @@ pub fn build_impl_object(args: TokenStream, body: TokenStream, is_internal: bool .unwrap_or(false) { resolve_parts.push(quote!( let #arg_ident = executor.context(); )); - } + } // Make sure the user does not specify the Context // without a reference. (&Context) - else if context_type.clone().map(|ctx| ctx == &captured.ty).unwrap_or(false) { + else if context_type + .clone() + .map(|ctx| ctx == &captured.ty) + .unwrap_or(false) + { panic!( "Invalid context argument: to access the context, you need to specify the type as a reference.\nDid you mean &{}?", quote!(captured.ty), ); - } - else { + } else { let ty = &captured.ty; // TODO: respect graphql attribute overwrite. let final_name = util::to_camel_case(&arg_name); diff --git a/juniper_codegen/src/lib.rs b/juniper_codegen/src/lib.rs index a086bc28..66e334bb 100644 --- a/juniper_codegen/src/lib.rs +++ b/juniper_codegen/src/lib.rs @@ -79,16 +79,16 @@ pub fn derive_scalar_value_internal(input: TokenStream) -> TokenStream { The `impl_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 +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 +`impl_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 `impl_object`. More advanced use cases are introduced step by step. ``` @@ -105,17 +105,17 @@ impl Query { // This defines a simple, static field which does not require any context. - // You can return any value that implements the `GraphQLType` trait. + // You can return any value that implements the `GraphQLType` trait. // This trait is implemented for: // - 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. - // - // An important note regarding naming: + // + // An important note regarding naming: // By default, field names will be converted to camel case. // For your GraphQL queries, the field will be available as `apiVersion`. - // + // // You can also manually customize the field name if required. (See below) fn api_version() -> &'static str { "0.1" @@ -169,7 +169,7 @@ You can specify a context that will be available across all your resolvers during query execution. The Context can be injected into your resolvers by just -specifying an argument with the same type as the context +specifying an argument with the same type as the context (but as a reference). ``` @@ -198,11 +198,11 @@ impl Query { context.db.user(id) } - // You can also gain access to the executor, which + // You can also gain access to the executor, which // allows you to do look aheads. fn with_executor(executor: &Executor) -> bool { let info = executor.look_ahead(); - // ... + // ... true } } diff --git a/juniper_codegen/src/util.rs b/juniper_codegen/src/util.rs index 930c0129..44a65fbb 100644 --- a/juniper_codegen/src/util.rs +++ b/juniper_codegen/src/util.rs @@ -611,7 +611,7 @@ pub struct GraphQLTypeDefiniton { // This flag signifies if the type generics need to be // included manually. pub include_type_generics: bool, - // This flag indicates if the generated code should always be + // This flag indicates if the generated code should always be // generic over the ScalarValue. // If false, the scalar is only generic if a generic parameter // is specified manually. @@ -744,7 +744,7 @@ impl GraphQLTypeDefiniton { // A custom scalar type was specified. // Therefore, we always insert a where clause that marks the scalar as // compatible with ScalarValueRef. - // This is done to prevent the user from having to specify this + // This is done to prevent the user from having to specify this // manually. let where_clause = generics.where_clause.get_or_insert(parse_quote!(where)); where_clause.predicates.push( @@ -764,9 +764,9 @@ impl GraphQLTypeDefiniton { // Insert a where clause that marks the scalar as // compatible with ScalarValueRef. // Same as in branch above. - where_clause.predicates.push( - parse_quote!(for<'__b> &'__b __S: #juniper_crate_name::ScalarRefValue<'__b>), - ); + where_clause + .predicates + .push(parse_quote!(for<'__b> &'__b __S: #juniper_crate_name::ScalarRefValue<'__b>)); } let type_generics_tokens = if self.include_type_generics {