Yay! Static fields, finally, minimally resolving [skip ci]
This commit is contained in:
parent
0b6544db48
commit
2d01486ee9
3 changed files with 34 additions and 19 deletions
|
@ -141,7 +141,7 @@ impl<'a, S: ScalarValue + 'a> SchemaType<'a, S> {
|
||||||
self.description.as_deref()
|
self.description.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn types(&self) -> Vec<TypeType<S>> {
|
fn types(&self) -> Vec<TypeType<'_, S>> {
|
||||||
self.type_list()
|
self.type_list()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|t| {
|
.filter(|t| {
|
||||||
|
@ -156,21 +156,21 @@ impl<'a, S: ScalarValue + 'a> SchemaType<'a, S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[graphql(name = "queryType")]
|
#[graphql(name = "queryType")]
|
||||||
fn query_type_(&self) -> TypeType<S> {
|
fn query_type_(&self) -> TypeType<'_, S> {
|
||||||
self.query_type()
|
self.query_type()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[graphql(name = "mutationType")]
|
#[graphql(name = "mutationType")]
|
||||||
fn mutation_type_(&self) -> Option<TypeType<S>> {
|
fn mutation_type_(&self) -> Option<TypeType<'_, S>> {
|
||||||
self.mutation_type()
|
self.mutation_type()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[graphql(name = "subscriptionType")]
|
#[graphql(name = "subscriptionType")]
|
||||||
fn subscription_type_(&self) -> Option<TypeType<S>> {
|
fn subscription_type_(&self) -> Option<TypeType<'_, S>> {
|
||||||
self.subscription_type()
|
self.subscription_type()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn directives(&self) -> Vec<&DirectiveType<S>> {
|
fn directives(&self) -> Vec<&DirectiveType<'_, S>> {
|
||||||
self.directive_list()
|
self.directive_list()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ impl<'a, S: ScalarValue + 'a> TypeType<'a, S> {
|
||||||
fn fields(
|
fn fields(
|
||||||
&self,
|
&self,
|
||||||
#[graphql(default = false)] include_deprecated: Option<bool>,
|
#[graphql(default = false)] include_deprecated: Option<bool>,
|
||||||
) -> Option<Vec<&Field<S>>> {
|
) -> Option<Vec<&Field<'_, S>>> {
|
||||||
match self {
|
match self {
|
||||||
TypeType::Concrete(&MetaType::Interface(InterfaceMeta { ref fields, .. }))
|
TypeType::Concrete(&MetaType::Interface(InterfaceMeta { ref fields, .. }))
|
||||||
| TypeType::Concrete(&MetaType::Object(ObjectMeta { ref fields, .. })) => Some(
|
| TypeType::Concrete(&MetaType::Object(ObjectMeta { ref fields, .. })) => Some(
|
||||||
|
@ -231,14 +231,14 @@ impl<'a, S: ScalarValue + 'a> TypeType<'a, S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn of_type(&self) -> Option<&TypeType<S>> {
|
fn of_type(&self) -> Option<&TypeType<'_, S>> {
|
||||||
match self {
|
match self {
|
||||||
TypeType::Concrete(_) => None,
|
TypeType::Concrete(_) => None,
|
||||||
TypeType::List(l, _) | TypeType::NonNull(l) => Some(&**l),
|
TypeType::List(l, _) | TypeType::NonNull(l) => Some(&**l),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn input_fields(&self) -> Option<&[Argument<S>]> {
|
fn input_fields(&self) -> Option<&[Argument<'_, S>]> {
|
||||||
match self {
|
match self {
|
||||||
TypeType::Concrete(&MetaType::InputObject(InputObjectMeta {
|
TypeType::Concrete(&MetaType::InputObject(InputObjectMeta {
|
||||||
ref input_fields,
|
ref input_fields,
|
||||||
|
@ -343,7 +343,7 @@ impl<'a, S: ScalarValue + 'a> Field<'a, S> {
|
||||||
self.description.as_deref()
|
self.description.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args(&self) -> Vec<&Argument<S>> {
|
fn args(&self) -> Vec<&Argument<'_, S>> {
|
||||||
self.arguments
|
self.arguments
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or_else(Vec::new, |v| v.iter().collect())
|
.map_or_else(Vec::new, |v| v.iter().collect())
|
||||||
|
@ -434,7 +434,7 @@ impl<'a, S: ScalarValue + 'a> DirectiveType<'a, S> {
|
||||||
self.is_repeatable
|
self.is_repeatable
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args(&self) -> &[Argument<S>] {
|
fn args(&self) -> &[Argument<'_, S>] {
|
||||||
&self.arguments
|
&self.arguments
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,9 +124,16 @@ pub(crate) trait TypeExt {
|
||||||
/// inferring.
|
/// inferring.
|
||||||
fn lifetimes_anonymized(&mut self);
|
fn lifetimes_anonymized(&mut self);
|
||||||
|
|
||||||
|
/// Anonymizes all the lifetime parameters of this [`syn::Type`] (except
|
||||||
|
/// the `'static` ones), making it suitable for using in contexts with
|
||||||
|
/// inferring, and returns it as a new type, leaving the original one
|
||||||
|
/// unchanged.
|
||||||
|
fn to_anonymized_lifetimes(&self) -> syn::Type;
|
||||||
|
|
||||||
/// Lifts all the lifetimes of this [`syn::Type`] (even elided, but except
|
/// Lifts all the lifetimes of this [`syn::Type`] (even elided, but except
|
||||||
/// `'static`) to a `for<>` quantifier, preserving the type speciality as
|
/// `'static`) to a `for<>` quantifier, preserving the type speciality as
|
||||||
/// much as possible.
|
/// much as possible, and returns it as a new type, leaving the original one
|
||||||
|
/// unchanged.
|
||||||
fn to_hrtb_lifetimes(&self) -> (Option<syn::BoundLifetimes>, syn::Type);
|
fn to_hrtb_lifetimes(&self) -> (Option<syn::BoundLifetimes>, syn::Type);
|
||||||
|
|
||||||
/// Returns the topmost [`syn::Ident`] of this [`syn::TypePath`], if any.
|
/// Returns the topmost [`syn::Ident`] of this [`syn::TypePath`], if any.
|
||||||
|
@ -233,6 +240,12 @@ impl TypeExt for syn::Type {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_anonymized_lifetimes(&self) -> syn::Type {
|
||||||
|
let mut ty = self.clone();
|
||||||
|
ty.lifetimes_anonymized();
|
||||||
|
ty
|
||||||
|
}
|
||||||
|
|
||||||
fn to_hrtb_lifetimes(&self) -> (Option<syn::BoundLifetimes>, syn::Type) {
|
fn to_hrtb_lifetimes(&self) -> (Option<syn::BoundLifetimes>, syn::Type) {
|
||||||
let mut ty = self.clone();
|
let mut ty = self.clone();
|
||||||
let mut lts = vec![];
|
let mut lts = vec![];
|
||||||
|
|
|
@ -21,7 +21,7 @@ use crate::common::{
|
||||||
behavior, field, filter_attrs, gen,
|
behavior, field, filter_attrs, gen,
|
||||||
parse::{
|
parse::{
|
||||||
attr::{err, OptionExt as _},
|
attr::{err, OptionExt as _},
|
||||||
GenericsExt as _, ParseBufferExt as _, TypeExt,
|
GenericsExt as _, ParseBufferExt as _, TypeExt as _,
|
||||||
},
|
},
|
||||||
rename, scalar, Description, SpanContainer,
|
rename, scalar, Description, SpanContainer,
|
||||||
};
|
};
|
||||||
|
@ -626,15 +626,18 @@ impl<Operation: ?Sized + 'static> Definition<Operation> {
|
||||||
let (f_ident, f_ty) = (&field.ident, &field.ty);
|
let (f_ident, f_ty) = (&field.ident, &field.ty);
|
||||||
|
|
||||||
let body = if !field.is_async {
|
let body = if !field.is_async {
|
||||||
|
let (f_for_ty, f_hrtb_ty) = f_ty.to_hrtb_lifetimes();
|
||||||
generics.make_where_clause().predicates.push(parse_quote! {
|
generics.make_where_clause().predicates.push(parse_quote! {
|
||||||
#f_ty: ::juniper::resolve::Resolvable<#sv, #f_bh>
|
#f_for_ty #f_hrtb_ty:
|
||||||
|
::juniper::resolve::Resolvable<#sv, #f_bh>
|
||||||
});
|
});
|
||||||
generics.make_where_clause().predicates.push(parse_quote! {
|
generics.make_where_clause().predicates.push(parse_quote! {
|
||||||
<#f_ty as ::juniper::resolve::Resolvable<#sv, #f_bh>>::Value:
|
#f_for_ty <#f_hrtb_ty as ::juniper::resolve::Resolvable<#sv, #f_bh>>::Value:
|
||||||
::juniper::resolve::Value<#inf, #cx, #sv, #f_bh>
|
::juniper::resolve::Value<#inf, #cx, #sv, #f_bh>
|
||||||
});
|
});
|
||||||
|
|
||||||
let res = if field.is_method() {
|
let val = if field.is_method() {
|
||||||
|
let f_anon_ty = f_ty.to_anonymized_lifetimes();
|
||||||
let args = field
|
let args = field
|
||||||
.arguments
|
.arguments
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -666,23 +669,22 @@ impl<Operation: ?Sized + 'static> Definition<Operation> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let rcv = field.has_receiver.then(|| {
|
let rcv = field.has_receiver.then(|| {
|
||||||
quote! { self, }
|
quote! { self, }
|
||||||
});
|
});
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
<#f_ty as ::juniper::resolve::Resolvable<#sv, #f_bh>>
|
<#f_anon_ty as ::juniper::resolve::Resolvable<#sv, #f_bh>>
|
||||||
::into_value(Self::#f_ident(#rcv #( #args ),*))?
|
::into_value(Self::#f_ident(#rcv #( #args ),*))?
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
&self.#f_ident
|
self.#f_ident
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
executor.resolve_value::<#f_bh, _, _>(#res, type_info)
|
executor.resolve_value::<#f_bh, _, _>(&#val, type_info)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
|
|
Loading…
Reference in a new issue