Support multiple lines of rustdoc as a type description.
This commit is contained in:
parent
6cda0644c6
commit
76b582065d
|
@ -222,17 +222,25 @@ pub fn parse_guards(crate_name: &TokenStream, args: &MetaList) -> Result<Option<
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_rustdoc(attrs: &[Attribute]) -> Result<Option<String>> {
|
pub fn get_rustdoc(attrs: &[Attribute]) -> Result<Option<String>> {
|
||||||
|
let mut full_docs = String::new();
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
match attr.parse_meta()? {
|
match attr.parse_meta()? {
|
||||||
Meta::NameValue(nv) if nv.path.is_ident("doc") => {
|
Meta::NameValue(nv) if nv.path.is_ident("doc") => {
|
||||||
if let Lit::Str(doc) = nv.lit {
|
if let Lit::Str(doc) = nv.lit {
|
||||||
let doc = doc.value();
|
let doc = doc.value();
|
||||||
let doc_str = doc.trim();
|
let doc_str = doc.trim();
|
||||||
return Ok(Some(doc_str.to_string()));
|
if !full_docs.is_empty() {
|
||||||
|
full_docs += "\n";
|
||||||
|
}
|
||||||
|
full_docs += doc_str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(if full_docs.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(full_docs)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,6 +144,8 @@ struct Mutation;
|
||||||
#[Object(desc = "Global mutation")]
|
#[Object(desc = "Global mutation")]
|
||||||
impl Mutation {
|
impl Mutation {
|
||||||
/// simple_mutation description
|
/// simple_mutation description
|
||||||
|
/// line2
|
||||||
|
/// line3
|
||||||
async fn simple_mutation(&self, _input: SimpleInput) -> SimpleObject {
|
async fn simple_mutation(&self, _input: SimpleInput) -> SimpleObject {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
@ -919,7 +921,7 @@ pub async fn test_introspection_mutation() {
|
||||||
"description": "Global mutation",
|
"description": "Global mutation",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"description": "simple_mutation description",
|
"description": "simple_mutation description\nline2\nline3",
|
||||||
"name": "simpleMutation",
|
"name": "simpleMutation",
|
||||||
"type": {
|
"type": {
|
||||||
"kind": "NON_NULL",
|
"kind": "NON_NULL",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user