Correct fully qualified paths in generated code (#1195, #1194)

This commit is contained in:
tyranron 2023-10-13 19:28:42 +03:00
parent 801820a3b6
commit 17a02fa766
No known key found for this signature in database
GPG key ID: 762E144FB230A4F0
15 changed files with 120 additions and 60 deletions

View file

@ -516,7 +516,7 @@ macro_rules! assert_implemented_for {
<$implementor as $crate::macros::reflect::BaseType<$scalar>>::NAME, <$implementor as $crate::macros::reflect::BaseType<$scalar>>::NAME,
"`: missing implementer reference in interface's `for` attribute.", "`: missing implementer reference in interface's `for` attribute.",
); );
::std::panic!("{}", MSG); ::core::panic!("{}", MSG);
} }
})* })*
}; };
@ -544,7 +544,7 @@ macro_rules! assert_interfaces_impls {
<$implementers as $crate::macros::reflect::BaseType<$scalar>>::NAME, <$implementers as $crate::macros::reflect::BaseType<$scalar>>::NAME,
"`: missing interface reference in implementer's `impl` attribute.", "`: missing interface reference in implementer's `impl` attribute.",
); );
::std::panic!("{}", MSG); ::core::panic!("{}", MSG);
} }
})* })*
}; };
@ -576,7 +576,7 @@ macro_rules! assert_transitive_impls {
<$implementor as $crate::macros::reflect::BaseType<$scalar>>::NAME, <$implementor as $crate::macros::reflect::BaseType<$scalar>>::NAME,
"`." "`."
); );
::std::panic!("{}", MSG); ::core::panic!("{}", MSG);
} }
})* })*
}; };
@ -674,7 +674,7 @@ macro_rules! assert_subtype {
$crate::format_type!(BASE_RETURN_TY, BASE_RETURN_WRAPPED_VAL), $crate::format_type!(BASE_RETURN_TY, BASE_RETURN_WRAPPED_VAL),
"`.", "`.",
); );
::std::panic!("{}", MSG); ::core::panic!("{}", MSG);
} }
}; };
}; };
@ -855,7 +855,7 @@ macro_rules! assert_field_args {
}; };
const ERROR_MSG: &str = const ERROR_MSG: &str =
$crate::const_concat!(ERR_PREFIX, "Field `", FIELD_NAME, "`: ", MSG); $crate::const_concat!(ERR_PREFIX, "Field `", FIELD_NAME, "`: ", MSG);
::std::panic!("{}", ERROR_MSG); ::core::panic!("{}", ERROR_MSG);
} }
}; };
}; };
@ -911,7 +911,7 @@ macro_rules! checked_hash {
<$impl_ty as $crate::macros::reflect::BaseType<$scalar>>::NAME, <$impl_ty as $crate::macros::reflect::BaseType<$scalar>>::NAME,
"`." "`."
); );
::std::panic!("{}", MSG) ::core::panic!("{}", MSG)
} }
}}; }};
} }

View file

@ -102,12 +102,12 @@ impl Directive {
impl ToTokens for Directive { impl ToTokens for Directive {
fn to_tokens(&self, into: &mut TokenStream) { fn to_tokens(&self, into: &mut TokenStream) {
let reason = self.reason.as_ref().map_or_else( let reason = self
|| quote! { ::core::option::Option::None }, .reason
|text| quote! { ::core::option::Option::Some(#text) }, .as_ref()
); .map_or_else(|| quote! { None }, |text| quote! { Some(#text) });
quote! { quote! {
.deprecated(#reason) .deprecated(::core::option::Option::#reason)
} }
.to_tokens(into); .to_tokens(into);
} }

View file

@ -341,7 +341,9 @@ impl OnMethod {
quote! { quote! {
match #arg { match #arg {
::core::result::Result::Ok(v) => v, ::core::result::Result::Ok(v) => v,
::core::result::Result::Err(e) => return ::std::boxed::Box::pin(async { ::core::result::Result::Err(e) }), ::core::result::Result::Err(e) => return ::std::boxed::Box::pin(async {
::core::result::Result::Err(e)
}),
} }
} }
} else { } else {

View file

@ -354,14 +354,20 @@ impl Definition {
async move { async move {
let ex = executor.as_executor(); let ex = executor.as_executor();
match res2 { match res2 {
::core::result::Result::Ok(::core::option::Option::Some((ctx, r))) => { ::core::result::Result::Ok(
::core::option::Option::Some((ctx, r)),
) => {
let sub = ex.replaced_context(ctx); let sub = ex.replaced_context(ctx);
sub.resolve_with_ctx_async(&(), &r) sub.resolve_with_ctx_async(&(), &r)
.await .await
.map_err(|e| ex.new_error(e)) .map_err(|e| ex.new_error(e))
} }
::core::result::Result::Ok(::core::option::Option::None) => ::core::result::Result::Ok(::juniper::Value::null()), ::core::result::Result::Ok(::core::option::Option::None) => {
::core::result::Result::Err(e) => ::core::result::Result::Err(ex.new_error(e)), ::core::result::Result::Ok(::juniper::Value::null())
}
::core::result::Result::Err(e) => {
::core::result::Result::Err(ex.new_error(e))
}
} }
} }
}); });

View file

@ -13,8 +13,12 @@ pub(crate) fn sync_resolving_code() -> TokenStream {
quote! { quote! {
::juniper::IntoResolvable::into_resolvable(res, executor.context()) ::juniper::IntoResolvable::into_resolvable(res, executor.context())
.and_then(|res| match res { .and_then(|res| match res {
::core::option::Option::Some((ctx, r)) => executor.replaced_context(ctx).resolve_with_ctx(info, &r), ::core::option::Option::Some((ctx, r)) => {
::core::option::Option::None => ::core::result::Result::Ok(::juniper::Value::null()), executor.replaced_context(ctx).resolve_with_ctx(info, &r)
}
::core::option::Option::None => {
::core::result::Result::Ok(::juniper::Value::null())
}
}) })
} }
} }
@ -39,8 +43,10 @@ pub(crate) fn async_resolving_code(ty: Option<&syn::Type>) -> TokenStream {
::core::option::Option::Some((ctx, r)) => { ::core::option::Option::Some((ctx, r)) => {
let subexec = executor.replaced_context(ctx); let subexec = executor.replaced_context(ctx);
subexec.resolve_with_ctx_async(info, &r).await subexec.resolve_with_ctx_async(info, &r).await
}, }
::core::option::Option::None => ::core::result::Result::Ok(::juniper::Value::null()), ::core::option::Option::None => {
::core::result::Result::Ok(::juniper::Value::null())
}
} }
})) }))
} }

View file

@ -450,7 +450,9 @@ impl Definition {
for #ident #ty_generics for #ident #ty_generics
#where_clause #where_clause
{ {
fn name(_ : &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { fn name(
_ : &Self::TypeInfo,
) -> ::core::option::Option<&'static ::core::primitive::str> {
::core::option::Option::Some(#name) ::core::option::Option::Some(#name)
} }
@ -489,7 +491,9 @@ impl Definition {
let name = &v.name; let name = &v.name;
quote! { quote! {
Self::#ident => ::core::result::Result::Ok(::juniper::Value::scalar(::std::string::String::from(#name))), Self::#ident => ::core::result::Result::Ok(::juniper::Value::scalar(
::std::string::String::from(#name),
)),
} }
}); });
@ -509,7 +513,10 @@ impl Definition {
type Context = #context; type Context = #context;
type TypeInfo = (); type TypeInfo = ();
fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> ::core::option::Option<&'__i ::core::primitive::str> { fn type_name<'__i>(
&self,
info: &'__i Self::TypeInfo,
) -> ::core::option::Option<&'__i ::core::primitive::str> {
<Self as ::juniper::GraphQLType<#scalar>>::name(info) <Self as ::juniper::GraphQLType<#scalar>>::name(info)
} }
@ -588,10 +595,14 @@ impl Definition {
{ {
type Error = ::std::string::String; type Error = ::std::string::String;
fn from_input_value(v: &::juniper::InputValue<#scalar>) -> ::core::result::Result<Self, Self::Error> { fn from_input_value(
v: &::juniper::InputValue<#scalar>,
) -> ::core::result::Result<Self, Self::Error> {
match v.as_enum_value().or_else(|| v.as_string_value()) { match v.as_enum_value().or_else(|| v.as_string_value()) {
#( #variants )* #( #variants )*
_ => ::core::result::Result::Err(::std::format!("Unknown enum value: {}", v)), _ => ::core::result::Result::Err(
::std::format!("Unknown enum value: {}", v),
),
} }
} }
} }

View file

@ -479,7 +479,9 @@ impl Definition {
for #ident #ty_generics for #ident #ty_generics
#where_clause #where_clause
{ {
fn name(_: &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { fn name(
_: &Self::TypeInfo,
) -> ::core::option::Option<&'static ::core::primitive::str> {
::core::option::Option::Some(#name) ::core::option::Option::Some(#name)
} }
@ -524,7 +526,10 @@ impl Definition {
type Context = #context; type Context = #context;
type TypeInfo = (); type TypeInfo = ();
fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> ::core::option::Option<&'__i ::core::primitive::str> { fn type_name<'__i>(
&self,
info: &'__i Self::TypeInfo,
) -> ::core::option::Option<&'__i ::core::primitive::str> {
<Self as ::juniper::GraphQLType<#scalar>>::name(info) <Self as ::juniper::GraphQLType<#scalar>>::name(info)
} }
} }

View file

@ -460,7 +460,9 @@ impl Definition {
syn::GenericParam::Const(_) => return None, syn::GenericParam::Const(_) => return None,
}; };
Some(quote! { Some(quote! {
::core::marker::PhantomData<::std::sync::atomic::AtomicPtr<std::boxed::Box<#ty>>> ::core::marker::PhantomData<
::core::sync::atomic::AtomicPtr<std::boxed::Box<#ty>>
>
}) })
}); });
quote! { __Phantom(#(#phantom_params),*) } quote! { __Phantom(#(#phantom_params),*) }
@ -474,7 +476,7 @@ impl Definition {
.map(|(ty, ident)| { .map(|(ty, ident)| {
quote! { quote! {
#[automatically_derived] #[automatically_derived]
impl #interface_impl_gens ::std::convert::From<#ty> impl #interface_impl_gens ::core::convert::From<#ty>
for #alias_ident #interface_ty_gens for #alias_ident #interface_ty_gens
#interface_where_clause #interface_where_clause
{ {
@ -487,7 +489,7 @@ impl Definition {
quote! { quote! {
#[automatically_derived] #[automatically_derived]
#[derive(::std::clone::Clone, ::core::marker::Copy, ::std::fmt::Debug)] #[derive(::core::clone::Clone, ::core::marker::Copy, ::core::fmt::Debug)]
#[doc = #enum_doc] #[doc = #enum_doc]
#vis enum #enum_ident #enum_gens { #vis enum #enum_ident #enum_gens {
#( #[doc(hidden)] #variants_idents(#variant_gens_pars), )* #( #[doc(hidden)] #variants_idents(#variant_gens_pars), )*
@ -715,8 +717,10 @@ impl Definition {
for #ty #ty_generics for #ty #ty_generics
#where_clause #where_clause
{ {
fn name(_ : &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { fn name(
::std::option::Option::Some(#name) _ : &Self::TypeInfo,
) -> ::core::option::Option<&'static ::core::primitive::str> {
::core::option::Option::Some(#name)
} }
fn meta<'r>( fn meta<'r>(
@ -784,7 +788,10 @@ impl Definition {
type Context = #context; type Context = #context;
type TypeInfo = (); type TypeInfo = ();
fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> std::option::Option<&'__i ::core::primitive::str> { fn type_name<'__i>(
&self,
info: &'__i Self::TypeInfo,
) -> ::core::option::Option<&'__i ::core::primitive::str> {
<Self as ::juniper::GraphQLType<#scalar>>::name(info) <Self as ::juniper::GraphQLType<#scalar>>::name(info)
} }

View file

@ -457,7 +457,9 @@ impl<Operation: ?Sized + 'static> Definition<Operation> {
#[automatically_derived] #[automatically_derived]
impl #impl_generics ::juniper::GraphQLType<#scalar> for #ty #where_clause impl #impl_generics ::juniper::GraphQLType<#scalar> for #ty #where_clause
{ {
fn name(_ : &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { fn name(
_ : &Self::TypeInfo,
) -> ::core::option::Option<&'static ::core::primitive::str> {
::core::option::Option::Some(#name) ::core::option::Option::Some(#name)
} }
@ -626,7 +628,7 @@ impl Definition<Query> {
let resolve = if field.is_async { let resolve = if field.is_async {
quote! { quote! {
::std::panic!( ::core::panic!(
"Tried to resolve async field `{}` on type `{}` with a sync resolver", "Tried to resolve async field `{}` on type `{}` with a sync resolver",
#name, #name,
<Self as ::juniper::macros::reflect::BaseType<#scalar>>::NAME, <Self as ::juniper::macros::reflect::BaseType<#scalar>>::NAME,
@ -783,7 +785,10 @@ impl Definition<Query> {
type Context = #context; type Context = #context;
type TypeInfo = (); type TypeInfo = ();
fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> ::core::option::Option<&'__i ::core::primitive::str> { fn type_name<'__i>(
&self,
info: &'__i Self::TypeInfo,
) -> ::core::option::Option<&'__i ::core::primitive::str> {
<Self as ::juniper::GraphQLType<#scalar>>::name(info) <Self as ::juniper::GraphQLType<#scalar>>::name(info)
} }

View file

@ -375,7 +375,9 @@ impl Definition {
impl #impl_gens ::juniper::GraphQLType<#scalar> for #ty impl #impl_gens ::juniper::GraphQLType<#scalar> for #ty
#where_clause #where_clause
{ {
fn name(_: &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { fn name(
_: &Self::TypeInfo,
) -> ::core::option::Option<&'static ::core::primitive::str> {
::core::option::Option::Some(#name) ::core::option::Option::Some(#name)
} }
@ -416,7 +418,10 @@ impl Definition {
type Context = (); type Context = ();
type TypeInfo = (); type TypeInfo = ();
fn type_name<'i>(&self, info: &'i Self::TypeInfo) -> ::core::option::Option<&'i ::core::primitive::str> { fn type_name<'i>(
&self,
info: &'i Self::TypeInfo,
) -> ::core::option::Option<&'i ::core::primitive::str> {
<Self as ::juniper::GraphQLType<#scalar>>::name(info) <Self as ::juniper::GraphQLType<#scalar>>::name(info)
} }
@ -454,9 +459,8 @@ impl Definition {
selection_set: ::core::option::Option<&'b [::juniper::Selection<'_, #scalar>]>, selection_set: ::core::option::Option<&'b [::juniper::Selection<'_, #scalar>]>,
executor: &'b ::juniper::Executor<'_, '_, Self::Context, #scalar>, executor: &'b ::juniper::Executor<'_, '_, Self::Context, #scalar>,
) -> ::juniper::BoxFuture<'b, ::juniper::ExecutionResult<#scalar>> { ) -> ::juniper::BoxFuture<'b, ::juniper::ExecutionResult<#scalar>> {
use ::juniper::futures::future;
let v = ::juniper::GraphQLValue::resolve(self, info, selection_set, executor); let v = ::juniper::GraphQLValue::resolve(self, info, selection_set, executor);
::std::boxed::Box::pin(future::ready(v)) ::std::boxed::Box::pin(::juniper::futures::future::ready(v))
} }
} }
} }
@ -507,7 +511,9 @@ impl Definition {
{ {
type Error = ::juniper::executor::FieldError<#scalar>; type Error = ::juniper::executor::FieldError<#scalar>;
fn from_input_value(input: &::juniper::InputValue<#scalar>) -> ::core::result::Result<Self, Self::Error> { fn from_input_value(
input: &::juniper::InputValue<#scalar>,
) -> ::core::result::Result<Self, Self::Error> {
#from_input_value #from_input_value
.map_err(::juniper::executor::IntoFieldError::<#scalar>::into_field_error) .map_err(::juniper::executor::IntoFieldError::<#scalar>::into_field_error)
} }

View file

@ -49,7 +49,10 @@ impl Definition<Subscription> {
type Context = #context; type Context = #context;
type TypeInfo = (); type TypeInfo = ();
fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> ::core::option::Option<&'__i ::core::primitive::str> { fn type_name<'__i>(
&self,
info: &'__i Self::TypeInfo,
) -> ::core::option::Option<&'__i ::core::primitive::str> {
<Self as ::juniper::GraphQLType<#scalar>>::name(info) <Self as ::juniper::GraphQLType<#scalar>>::name(info)
} }

View file

@ -203,7 +203,7 @@ fn parse_variant_from_trait_method(
// no other options here, until the `juniper::GraphQLType` itself will allow // no other options here, until the `juniper::GraphQLType` itself will allow
// to do it in some cleverer way. // to do it in some cleverer way.
let resolver_check = parse_quote! { let resolver_check = parse_quote! {
({ #resolver_code } as ::std::option::Option<&#ty>).is_some() ({ #resolver_code } as ::core::option::Option<&#ty>).is_some()
}; };
Some(VariantDefinition { Some(VariantDefinition {

View file

@ -151,12 +151,15 @@ fn parse_variant_from_enum_variant(
} }
} else { } else {
parse_quote! { parse_quote! {
match self { #enum_ident::#var_ident(ref v) => ::core::option::Option::Some(v), _ => ::core::option::Option::None, } match self {
#enum_ident::#var_ident(ref v) => ::core::option::Option::Some(v),
_ => ::core::option::Option::None,
}
} }
}; };
let resolver_check = parse_quote! { let resolver_check = parse_quote! {
matches!(self, #enum_path(_)) ::core::matches!(self, #enum_path(_))
}; };
Some(VariantDefinition { Some(VariantDefinition {

View file

@ -473,7 +473,9 @@ impl Definition {
#[automatically_derived] #[automatically_derived]
impl #impl_generics ::juniper::GraphQLType<#scalar> for #ty_full #where_clause impl #impl_generics ::juniper::GraphQLType<#scalar> for #ty_full #where_clause
{ {
fn name(_ : &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { fn name(
_ : &Self::TypeInfo,
) -> ::core::option::Option<&'static ::core::primitive::str> {
::core::option::Option::Some(#name) ::core::option::Option::Some(#name)
} }
@ -525,7 +527,10 @@ impl Definition {
type Context = #context; type Context = #context;
type TypeInfo = (); type TypeInfo = ();
fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> Option<&'__i ::core::primitive::str> { fn type_name<'__i>(
&self,
info: &'__i Self::TypeInfo,
) -> ::core::option::Option<&'__i ::core::primitive::str> {
<Self as ::juniper::GraphQLType<#scalar>>::name(info) <Self as ::juniper::GraphQLType<#scalar>>::name(info)
} }
@ -535,7 +540,7 @@ impl Definition {
info: &Self::TypeInfo, info: &Self::TypeInfo,
) -> ::std::string::String { ) -> ::std::string::String {
#( #match_variant_names )* #( #match_variant_names )*
::std::panic!( ::core::panic!(
"GraphQL union `{}` cannot be resolved into any of its \ "GraphQL union `{}` cannot be resolved into any of its \
variants in its current state", variants in its current state",
#name, #name,
@ -742,7 +747,9 @@ impl VariantDefinition {
return #resolving_code; return #resolving_code;
} }
} }
::core::option::Option::None => return ::juniper::macros::helper::err_unnamed_type_fut(#ty_name), ::core::option::Option::None => {
return ::juniper::macros::helper::err_unnamed_type_fut(#ty_name);
}
} }
} }
} }
@ -773,7 +780,7 @@ fn emerge_union_variants_from_attr(
// we have no other options here, until the `juniper::GraphQLType` // we have no other options here, until the `juniper::GraphQLType`
// itself will allow to do it in some cleverer way. // itself will allow to do it in some cleverer way.
let resolver_check = parse_quote! { let resolver_check = parse_quote! {
({ #resolver_code } as ::std::option::Option<&#ty>).is_some() ({ #resolver_code } as ::core::option::Option<&#ty>).is_some()
}; };
if let Some(var) = variants.iter_mut().find(|v| v.ty == ty) { if let Some(var) = variants.iter_mut().find(|v| v.ty == ty) {

View file

@ -261,7 +261,7 @@ impl Definition {
( (
Method::AsStr, Method::AsStr,
quote! { fn as_str(&self) -> ::core::option::Option<&::core::primitive::str> }, quote! { fn as_str(&self) -> ::core::option::Option<&::core::primitive::str> },
quote! { ::std::convert::AsRef::as_ref(v) }, quote! { ::core::convert::AsRef::as_ref(v) },
), ),
( (
Method::AsString, Method::AsString,
@ -332,7 +332,7 @@ impl Definition {
quote! { quote! {
#[automatically_derived] #[automatically_derived]
impl #impl_gen ::std::convert::From<#var_ty> for #ty_ident #ty_gen impl #impl_gen ::core::convert::From<#var_ty> for #ty_ident #ty_gen
#where_clause #where_clause
{ {
fn from(v: #var_ty) -> Self { fn from(v: #var_ty) -> Self {
@ -341,8 +341,8 @@ impl Definition {
} }
#[automatically_derived] #[automatically_derived]
impl #impl_gen ::std::convert::From<#ty_ident #ty_gen> for ::core::option::Option<#var_ty> impl #impl_gen ::core::convert::From<#ty_ident #ty_gen>
#where_clause for ::core::option::Option<#var_ty> #where_clause
{ {
fn from(ty: #ty_ident #ty_gen) -> Self { fn from(ty: #ty_ident #ty_gen) -> Self {
if let #ty_ident::#var_ident #var_field = ty { if let #ty_ident::#var_ident #var_field = ty {
@ -354,9 +354,8 @@ impl Definition {
} }
#[automatically_derived] #[automatically_derived]
impl #lf_impl_gen ::std::convert::From<&'___a #ty_ident #ty_gen> for impl #lf_impl_gen ::core::convert::From<&'___a #ty_ident #ty_gen>
::core::option::Option<&'___a #var_ty> for ::core::option::Option<&'___a #var_ty> #where_clause
#where_clause
{ {
fn from(ty: &'___a #ty_ident #ty_gen) -> Self { fn from(ty: &'___a #ty_ident #ty_gen) -> Self {
if let #ty_ident::#var_ident #var_field = ty { if let #ty_ident::#var_ident #var_field = ty {
@ -390,7 +389,7 @@ impl Definition {
.as_mut() .as_mut()
.unwrap() .unwrap()
.predicates .predicates
.push(parse_quote! { #var_ty: ::std::fmt::Display }); .push(parse_quote! { #var_ty: ::core::fmt::Display });
} }
} }
let (impl_gen, ty_gen, where_clause) = generics.split_for_impl(); let (impl_gen, ty_gen, where_clause) = generics.split_for_impl();
@ -403,15 +402,15 @@ impl Definition {
.as_ref() .as_ref()
.map_or_else(|| quote! { (v) }, |i| quote! { { #i: v } }); .map_or_else(|| quote! { (v) }, |i| quote! { { #i: v } });
quote! { Self::#var_ident #var_field => ::std::fmt::Display::fmt(v, f), } quote! { Self::#var_ident #var_field => ::core::fmt::Display::fmt(v, f), }
}); });
quote! { quote! {
#[automatically_derived] #[automatically_derived]
impl #impl_gen ::std::fmt::Display for #ident #ty_gen impl #impl_gen ::core::fmt::Display for #ident #ty_gen
#where_clause #where_clause
{ {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
match self { match self {
#( #arms )* #( #arms )*
} }