New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use rustdoc comments as graphql desc? #62
Comments
I'm not sure rust's procedural macros support this, but I'll add them if possible. 😁 |
I have confirmed the possibility and I will add it tomorrow. It is a very good suggestion, thank you.😀 |
I am very excited. Repeating the description twice is too annoying. It is very convenient to get the desc directly from rustdoc. |
I have completed this feature and updated the example code of https://github.com/async-graphql/examples/tree/master/models/starwars |
Please upgrade to version 1.11.0, which already contains this feature.😁 |
@sunli829 is it also possible to use the structs rustdocs? See the example below. #[derive(Deserialize, Debug)]
/// A company is a legal entity representing an association of people, whether natural,
/// legal or a mixture of both, with a specific objective/goal.
pub struct Company {}
#[Object]
impl Company {
/// Globally unique identifier of a company.
pub async fn id(&self) -> &ID {
todo!()
}
/// The company name.
pub async fn name(&self) -> String {
todo!()
}
} Docs are currently only generated if i add the rustdocs to And another question, is it possible to add docs to a generated |
I suppose for the first one we could add a derive macro trait Description {
fn description(&self) -> &'static str;
} And we could either have For the second one we could either:
|
Hm...for the second one, i think i would like the macro The first one, the trait, i think that won't work with IDE docs. I would really like to not need to replicate the docs from the With the following code, i get the docs shown by the IDE as a popup, see screenshot, but not in graphql. #[derive(Deserialize, Debug)]
/// A company is a legal entity representing an association of people, whether natural,
/// legal or a mixture of both, with a specific objective/goal.
pub struct Company {}
#[Object]
impl Company {
/// Globally unique identifier of a company.
pub async fn id(&self) -> &ID {
todo!()
}
} When i put the docs on the #[derive(Deserialize, Debug)]
pub struct Company {}
#[Object]
/// A company is a legal entity representing an association of people, whether natural,
/// legal or a mixture of both, with a specific objective/goal.
impl Company {
/// Globally unique identifier of a company.
pub async fn id(&self) -> &ID {
todo!()
}
} Ideally, docs that are on the struct should be used for graphql too. |
So what I meant for the first one is that you'd write: #[derive(Deserialize, Debug, async_graphql::Description)]
/// A company is a legal entity representing an association of people, whether natural,
/// legal or a mixture of both, with a specific objective/goal.
pub struct Company {}
#[Object(use_type_description)]
impl Company {
/// Globally unique identifier of a company.
pub async fn id(&self) -> &ID {
todo!()
}
} And in the expansion it would write: description: Some(<Self as ::async_graphql::Description>::description()>),
No, it won't - there is no way to change the actual Rustdoc attributes of another item. All that macro does is to add that doc string to a global list of doc strings for that type, so when you register the type in the schema it uses the global list of doc strings. I don't really like that solution because |
Ah...i misunderstood you. I am not really deep into the howto's of macros, so maybe the my question is somewhat silly. Currently, the Object macro reads the rustdocs of wherever it is put on? Can a macro read the rustdocs of another struct or is it restricted to where it is placed?
#[derive(ScalarWrapper)]
/// My super doc comment.
pub struct MyDateTime(DateTime); then one would easily get both, the IDE popup when working with that struct and the GraphQL docs. Ideally, the macro should use the name of the inner type for the graphql type, or at least make renaming possible. Maybe even two different wrapper macros, for a specific purpose. |
Yes
No, this is why we have to add another derive macro and use the trait to communicate between the two. I don't really like the |
I think this looks better. 😂 #[derive(Deserialize, Debug, async_graphql::Description)]
/// A company is a legal entity representing an association of people, whether natural,
/// legal or a mixture of both, with a specific objective/goal.
pub struct Company {}
#[Object(use_type_description)]
impl Company {
/// Globally unique identifier of a company.
pub async fn id(&self) -> &ID {
todo!()
}
} I think there is no need to add a wrapper type just to be able to shown the document in the IDE, which will cause more trouble. |
@Koxiaet Thanks for clarifying! @sunli829 The wrapper would be for overriding the docs of scalars that exist inside of |
Ah, this seems to be useful. |
Let me think about this wapper, I first add the |
Oh...i think we missed one, what about the generated |
While we are at it 😄 : I have been meaning to verify this as of v2.0.0, but if I recall correctly, graphql docs were not generated for enum variants and custom scalars. Is that still true? |
I am looking to replace juniper with this library and I was looking through the docs and it looks like all the examples use proc macro attributes to add a description. Is it currently (or planned) possible to parse rustdoc comments for the graphql description?
The text was updated successfully, but these errors were encountered: