Use name_of_type
in macro [skip ci]
This commit is contained in:
parent
245c351a73
commit
321c3af38d
1 changed files with 12 additions and 23 deletions
|
@ -41,29 +41,18 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = match impl_attrs.name.as_ref() {
|
|
||||||
Some(type_name) => type_name.clone(),
|
|
||||||
None => {
|
|
||||||
let error_msg = "Could not determine a name for the object type: specify one with #[juniper::object(name = \"SomeName\")";
|
|
||||||
|
|
||||||
let path = match &*_impl.self_ty {
|
let name =
|
||||||
syn::Type::Path(ref type_path) => &type_path.path,
|
if let Some(name) = impl_attrs.name.as_ref(){
|
||||||
syn::Type::Reference(ref reference) => match &*reference.elem {
|
name.to_string()
|
||||||
syn::Type::Path(ref type_path) => &type_path.path,
|
}
|
||||||
syn::Type::TraitObject(ref trait_obj) => {
|
else {
|
||||||
match trait_obj.bounds.iter().nth(0).unwrap() {
|
if let Some(ident) = util::name_of_type(&*_impl.self_ty) {
|
||||||
syn::TypeParamBound::Trait(ref trait_bound) => &trait_bound.path,
|
ident.to_string()
|
||||||
_ => panic!(error_msg),
|
} else {
|
||||||
}
|
panic!("Could not determine a name for the object type: specify one with #[juniper::object(name = \"SomeName\")");
|
||||||
}
|
}
|
||||||
_ => panic!(error_msg),
|
};
|
||||||
},
|
|
||||||
_ => panic!(error_msg),
|
|
||||||
};
|
|
||||||
|
|
||||||
path.segments.iter().last().unwrap().ident.to_string()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let target_type = *_impl.self_ty.clone();
|
let target_type = *_impl.self_ty.clone();
|
||||||
|
|
||||||
|
@ -72,7 +61,7 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) ->
|
||||||
.or(util::get_doc_comment(&_impl.attrs));
|
.or(util::get_doc_comment(&_impl.attrs));
|
||||||
|
|
||||||
let mut definition = util::GraphQLTypeDefiniton {
|
let mut definition = util::GraphQLTypeDefiniton {
|
||||||
name: name.to_string(),
|
name: name,
|
||||||
_type: target_type.clone(),
|
_type: target_type.clone(),
|
||||||
context: impl_attrs.context,
|
context: impl_attrs.context,
|
||||||
scalar: impl_attrs.scalar,
|
scalar: impl_attrs.scalar,
|
||||||
|
|
Loading…
Add table
Reference in a new issue