Support multiple lines of rustdoc as a type description.

This commit is contained in:
Sunli 2020-05-18 10:09:09 +08:00
parent 6cda0644c6
commit 76b582065d
2 changed files with 13 additions and 3 deletions

View File

@ -222,17 +222,25 @@ pub fn parse_guards(crate_name: &TokenStream, args: &MetaList) -> Result<Option<
}
pub fn get_rustdoc(attrs: &[Attribute]) -> Result<Option<String>> {
let mut full_docs = String::new();
for attr in attrs {
match attr.parse_meta()? {
Meta::NameValue(nv) if nv.path.is_ident("doc") => {
if let Lit::Str(doc) = nv.lit {
let doc = doc.value();
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)
})
}

View File

@ -144,6 +144,8 @@ struct Mutation;
#[Object(desc = "Global mutation")]
impl Mutation {
/// simple_mutation description
/// line2
/// line3
async fn simple_mutation(&self, _input: SimpleInput) -> SimpleObject {
unimplemented!()
}
@ -919,7 +921,7 @@ pub async fn test_introspection_mutation() {
"description": "Global mutation",
"fields": [
{
"description": "simple_mutation description",
"description": "simple_mutation description\nline2\nline3",
"name": "simpleMutation",
"type": {
"kind": "NON_NULL",