diff --git a/async-graphql-derive/src/enum.rs b/async-graphql-derive/src/enum.rs index 5841d7a3..dddc9660 100644 --- a/async-graphql-derive/src/enum.rs +++ b/async-graphql-derive/src/enum.rs @@ -162,8 +162,8 @@ pub fn generate(enum_args: &args::Enum, input: &DeriveInput) -> Result, _pos: #crate_name::Pos) -> #crate_name::Result<#crate_name::serde_json::Value> { - #crate_name::EnumType::resolve_enum(value) + async fn resolve(&self, _: &#crate_name::ContextSelectionSet<'_>, _pos: #crate_name::Pos) -> #crate_name::Result<#crate_name::serde_json::Value> { + #crate_name::EnumType::resolve_enum(self) } } }; diff --git a/async-graphql-derive/src/interface.rs b/async-graphql-derive/src/interface.rs index bd99731e..f78fce0d 100644 --- a/async-graphql-derive/src/interface.rs +++ b/async-graphql-derive/src/interface.rs @@ -299,8 +299,8 @@ pub fn generate(interface_args: &args::Interface, input: &DeriveInput) -> Result #[#crate_name::async_trait::async_trait] impl #generics #crate_name::OutputValueType for #ident #generics { - async fn resolve(value: &Self, ctx: &#crate_name::ContextSelectionSet<'_>, pos: #crate_name::Pos) -> #crate_name::Result<#crate_name::serde_json::Value> { - #crate_name::do_resolve(ctx, value).await + async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, pos: #crate_name::Pos) -> #crate_name::Result<#crate_name::serde_json::Value> { + #crate_name::do_resolve(ctx, self).await } } }; diff --git a/async-graphql-derive/src/lib.rs b/async-graphql-derive/src/lib.rs index 9c114953..89715105 100644 --- a/async-graphql-derive/src/lib.rs +++ b/async-graphql-derive/src/lib.rs @@ -172,11 +172,11 @@ pub fn Scalar(args: TokenStream, input: TokenStream) -> TokenStream { #[#crate_name::async_trait::async_trait] impl #generic #crate_name::OutputValueType for #self_ty #where_clause { async fn resolve( - value: &Self, + &self, _: &#crate_name::ContextSelectionSet<'_>, _pos: #crate_name::Pos, ) -> #crate_name::Result<#crate_name::serde_json::Value> { - value.to_json() + self.to_json() } } }; diff --git a/async-graphql-derive/src/object.rs b/async-graphql-derive/src/object.rs index 02d3952c..cb2f63a3 100644 --- a/async-graphql-derive/src/object.rs +++ b/async-graphql-derive/src/object.rs @@ -384,10 +384,11 @@ pub fn generate(object_args: &args::Object, item_impl: &mut ItemImpl) -> Result< resolvers.push(quote! { if ctx.name.as_str() == #field_name { + use #crate_name::OutputValueType; #guard #(#get_params)* let ctx_obj = ctx.with_selection_set(&ctx.selection_set); - return #crate_name::OutputValueType::resolve(&#resolve_obj, &ctx_obj, ctx.position).await; + return OutputValueType::resolve(&#resolve_obj, &ctx_obj, ctx.position).await; } }); @@ -478,8 +479,8 @@ pub fn generate(object_args: &args::Object, item_impl: &mut ItemImpl) -> Result< #[#crate_name::async_trait::async_trait] impl #generics #crate_name::OutputValueType for #self_ty #where_clause { - async fn resolve(value: &Self, ctx: &#crate_name::ContextSelectionSet<'_>, pos: #crate_name::Pos) -> #crate_name::Result<#crate_name::serde_json::Value> { - #crate_name::do_resolve(ctx, value).await + async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, pos: #crate_name::Pos) -> #crate_name::Result<#crate_name::serde_json::Value> { + #crate_name::do_resolve(ctx, self).await } } }; diff --git a/async-graphql-derive/src/simple_object.rs b/async-graphql-derive/src/simple_object.rs index 32b912b1..12c49dc9 100644 --- a/async-graphql-derive/src/simple_object.rs +++ b/async-graphql-derive/src/simple_object.rs @@ -184,8 +184,8 @@ pub fn generate(object_args: &args::Object, input: &mut DeriveInput) -> Result, _pos: #crate_name::Pos) -> #crate_name::Result<#crate_name::serde_json::Value> { - #crate_name::do_resolve(ctx, value).await + async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _pos: #crate_name::Pos) -> #crate_name::Result<#crate_name::serde_json::Value> { + #crate_name::do_resolve(ctx, self).await } } }; diff --git a/async-graphql-derive/src/union.rs b/async-graphql-derive/src/union.rs index 6147df86..8c9a7b53 100644 --- a/async-graphql-derive/src/union.rs +++ b/async-graphql-derive/src/union.rs @@ -125,8 +125,8 @@ pub fn generate(interface_args: &args::Interface, input: &DeriveInput) -> Result #[#crate_name::async_trait::async_trait] impl #generics #crate_name::OutputValueType for #ident #generics { - async fn resolve(value: &Self, ctx: &#crate_name::ContextSelectionSet<'_>, pos: #crate_name::Pos) -> #crate_name::Result<#crate_name::serde_json::Value> { - #crate_name::do_resolve(ctx, value).await + async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, pos: #crate_name::Pos) -> #crate_name::Result<#crate_name::serde_json::Value> { + #crate_name::do_resolve(ctx, self).await } } }; diff --git a/src/base.rs b/src/base.rs index 037e0bf5..ddeda504 100644 --- a/src/base.rs +++ b/src/base.rs @@ -57,11 +57,7 @@ pub trait InputValueType: Type + Sized { #[async_trait::async_trait] pub trait OutputValueType: Type { /// Resolve an output value to `serde_json::Value`. - async fn resolve( - value: &Self, - ctx: &ContextSelectionSet<'_>, - pos: Pos, - ) -> Result; + async fn resolve(&self, ctx: &ContextSelectionSet<'_>, pos: Pos) -> Result; } #[allow(missing_docs)] @@ -185,12 +181,8 @@ impl Type for &T { #[async_trait::async_trait] impl OutputValueType for &T { #[allow(clippy::trivially_copy_pass_by_ref)] - async fn resolve( - value: &Self, - ctx: &ContextSelectionSet<'_>, - pos: Pos, - ) -> Result { - T::resolve(*value, ctx, pos).await + async fn resolve(&self, ctx: &ContextSelectionSet<'_>, pos: Pos) -> Result { + T::resolve(*self, ctx, pos).await } } @@ -208,12 +200,8 @@ impl Type for Box { impl OutputValueType for Box { #[allow(clippy::trivially_copy_pass_by_ref)] #[allow(clippy::borrowed_box)] - async fn resolve( - value: &Self, - ctx: &ContextSelectionSet<'_>, - pos: Pos, - ) -> Result { - T::resolve(&*value, ctx, pos).await + async fn resolve(&self, ctx: &ContextSelectionSet<'_>, pos: Pos) -> Result { + T::resolve(&*self, ctx, pos).await } } @@ -230,12 +218,8 @@ impl Type for Arc { #[async_trait::async_trait] impl OutputValueType for Arc { #[allow(clippy::trivially_copy_pass_by_ref)] - async fn resolve( - value: &Self, - ctx: &ContextSelectionSet<'_>, - pos: Pos, - ) -> Result { - T::resolve(&*value, ctx, pos).await + async fn resolve(&self, ctx: &ContextSelectionSet<'_>, pos: Pos) -> Result { + T::resolve(&*self, ctx, pos).await } } @@ -256,11 +240,11 @@ impl Type for FieldResult { #[async_trait::async_trait] impl OutputValueType for FieldResult { async fn resolve( - value: &Self, + &self, ctx: &ContextSelectionSet<'_>, pos: Pos, ) -> crate::Result where { - match value.as_ref() { + match self { Ok(value) => Ok(OutputValueType::resolve(value, ctx, pos).await?), Err(err) => Err(err.clone().into_error_with_path( pos, diff --git a/src/scalars/string.rs b/src/scalars/string.rs index 3790c5f2..5a523bd8 100644 --- a/src/scalars/string.rs +++ b/src/scalars/string.rs @@ -52,11 +52,7 @@ impl<'a> Type for &'a str { #[async_trait::async_trait] impl<'a> OutputValueType for &'a str { - async fn resolve( - value: &Self, - _: &ContextSelectionSet<'_>, - _pos: Pos, - ) -> Result { - Ok((*value).into()) + async fn resolve(&self, _: &ContextSelectionSet<'_>, _pos: Pos) -> Result { + Ok((*self).into()) } } diff --git a/src/types/connection/connection_type.rs b/src/types/connection/connection_type.rs index 165d9b1d..52882f36 100644 --- a/src/types/connection/connection_type.rs +++ b/src/types/connection/connection_type.rs @@ -203,11 +203,7 @@ impl ObjectType impl OutputValueType for Connection { - async fn resolve( - value: &Self, - ctx: &ContextSelectionSet<'_>, - _pos: Pos, - ) -> Result { - do_resolve(ctx, value).await + async fn resolve(&self, ctx: &ContextSelectionSet<'_>, _pos: Pos) -> Result { + do_resolve(ctx, self).await } } diff --git a/src/types/connection/edge.rs b/src/types/connection/edge.rs index e5b2f46f..eee59dad 100644 --- a/src/types/connection/edge.rs +++ b/src/types/connection/edge.rs @@ -120,11 +120,7 @@ where T: OutputValueType + Send + Sync + 'a, E: ObjectType + Sync + Send + 'a, { - async fn resolve( - value: &Self, - ctx: &ContextSelectionSet<'_>, - _pos: Pos, - ) -> Result { - do_resolve(ctx, value).await + async fn resolve(&self, ctx: &ContextSelectionSet<'_>, _pos: Pos) -> Result { + do_resolve(ctx, self).await } } diff --git a/src/types/empty_mutation.rs b/src/types/empty_mutation.rs index 885f0e23..2e65b149 100644 --- a/src/types/empty_mutation.rs +++ b/src/types/empty_mutation.rs @@ -55,11 +55,7 @@ impl ObjectType for EmptyMutation { #[async_trait::async_trait] impl OutputValueType for EmptyMutation { - async fn resolve( - _value: &Self, - _ctx: &ContextSelectionSet<'_>, - pos: Pos, - ) -> Result { + async fn resolve(&self, _ctx: &ContextSelectionSet<'_>, pos: Pos) -> Result { Err(Error::Query { pos, path: None, diff --git a/src/types/empty_subscription.rs b/src/types/empty_subscription.rs index 911b0c61..7cb7438b 100644 --- a/src/types/empty_subscription.rs +++ b/src/types/empty_subscription.rs @@ -58,11 +58,7 @@ impl SubscriptionType for EmptySubscription { #[async_trait::async_trait] impl OutputValueType for EmptySubscription { - async fn resolve( - _value: &Self, - _ctx: &ContextSelectionSet<'_>, - pos: Pos, - ) -> Result { + async fn resolve(&self, _ctx: &ContextSelectionSet<'_>, pos: Pos) -> Result { Err(Error::Query { pos, path: None, diff --git a/src/types/list.rs b/src/types/list.rs index 307a10c7..060dc3dc 100644 --- a/src/types/list.rs +++ b/src/types/list.rs @@ -35,13 +35,9 @@ impl InputValueType for Vec { #[allow(clippy::ptr_arg)] #[async_trait::async_trait] impl OutputValueType for Vec { - async fn resolve( - value: &Self, - ctx: &ContextSelectionSet<'_>, - pos: Pos, - ) -> Result { - let mut futures = Vec::with_capacity(value.len()); - for (idx, item) in value.iter().enumerate() { + async fn resolve(&self, ctx: &ContextSelectionSet<'_>, pos: Pos) -> Result { + let mut futures = Vec::with_capacity(self.len()); + for (idx, item) in self.iter().enumerate() { let ctx_idx = ctx.with_index(idx); futures.push(async move { OutputValueType::resolve(item, &ctx_idx, pos).await }); } @@ -61,13 +57,9 @@ impl Type for &[T] { #[async_trait::async_trait] impl OutputValueType for &[T] { - async fn resolve( - value: &Self, - ctx: &ContextSelectionSet<'_>, - pos: Pos, - ) -> Result { - let mut futures = Vec::with_capacity(value.len()); - for (idx, item) in (*value).iter().enumerate() { + async fn resolve(&self, ctx: &ContextSelectionSet<'_>, pos: Pos) -> Result { + let mut futures = Vec::with_capacity(self.len()); + for (idx, item) in (*self).iter().enumerate() { let ctx_idx = ctx.with_index(idx); futures.push(async move { OutputValueType::resolve(item, &ctx_idx, pos).await }); } diff --git a/src/types/optional.rs b/src/types/optional.rs index d680add7..e2e4bc9e 100644 --- a/src/types/optional.rs +++ b/src/types/optional.rs @@ -29,12 +29,9 @@ impl InputValueType for Option { #[async_trait::async_trait] impl OutputValueType for Option { - async fn resolve( - value: &Self, - ctx: &ContextSelectionSet<'_>, - pos: Pos, - ) -> Result where { - if let Some(inner) = value { + async fn resolve(&self, ctx: &ContextSelectionSet<'_>, pos: Pos) -> Result where + { + if let Some(inner) = self { OutputValueType::resolve(inner, ctx, pos).await } else { Ok(serde_json::Value::Null) diff --git a/src/types/query_root.rs b/src/types/query_root.rs index 94ab92a8..6c8ed422 100644 --- a/src/types/query_root.rs +++ b/src/types/query_root.rs @@ -140,11 +140,7 @@ impl ObjectType for QueryRoot { #[async_trait::async_trait] impl OutputValueType for QueryRoot { - async fn resolve( - value: &Self, - ctx: &ContextSelectionSet<'_>, - _pos: Pos, - ) -> Result { - do_resolve(ctx, value).await + async fn resolve(&self, ctx: &ContextSelectionSet<'_>, _pos: Pos) -> Result { + do_resolve(ctx, self).await } }