Skip to content
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

[Feature Discussion] Graphql Documentation Generation #1516

Closed
John0x opened this issue Mar 5, 2020 · 13 comments · Fixed by #1524
Closed

[Feature Discussion] Graphql Documentation Generation #1516

John0x opened this issue Mar 5, 2020 · 13 comments · Fixed by #1524
Assignees
Labels
🗣 discussion 🎉 enhancement New feature or request 🎨 refactoring This issue is about doing refactoring work, like cleaning up the code making existing code better.
Milestone

Comments

@John0x
Copy link
Contributor

John0x commented Mar 5, 2020

Summary

Currently the XML Documentation is used to automatically generate graphql schema documentation, which already is pretty handy 👍
Though it can be improved in my opinion.
I personally like to include the errors/exceptions that can be thrown by the mutation/query in the documentation so that someone who consumes the API already knows what error codes he should handle.

The XML Documentation feature gives us a lot of handy elements that could be utilized to generate a great interactive documentation.
Elements that I'm interested in right now:

I'm willing to implement a more detailed documentation generation, but I might need some assistance since it would be my first hc contribution 🙂

Any thoughts on this?
Especially on how to format it and which elements should be converted.

Proposal

Current State

        /// <summary>
        /// Updates the user
        /// </summary>
        /// <param name="email">Email of the user</param>
        /// <param name="input">User DTO</param>
        /// <returns>User object of the updated user</returns>
        /// <exception cref="QueryException" code="USER_NOT_FOUND">Couldn't find user</exception>
        /// <exception cref="QueryException" code="DB_NOT_NULL_VIOLATION">General database not null violation</exception>
        /// <exception cref="QueryException" code="DB_UNIQUE_VIOLATION">General database unique violation</exception>
        /// <exception cref="QueryException" code="DB_UPDATE_EXCEPTION">General database update exception</exception>
        public async Task<User> UpdateUser(string email, UpdateUserInput input)
        {
            return await _userService.UpdateUser(email, input);
        }

Gets generated to:

  """
  Updates the user
  """
  updateUser(
    "Email of the user"
    email: String!
    "User DTO"
    input: UpdateUserInput!
  ): User!

Suggested State

Should get generated to:

  """
  Updates the user
  
  **Returns:** User object of the updated user
  
  **Errors:**
  1. USER_NOT_FOUND: Couldn't find user
  2. DB_NOT_NULL_VIOLATION: General database not null violation
  3. DB_UNIQUE_VIOLATION: General database unique violation
  4. DB_UPDATE_EXCEPTION: General database update exception
  """
  updateUser(
    "Email of the user"
    email: String!
    "User DTO"
    input: UpdateUserInput!
  ): User!

Links

Previous discussions:

Relevant documentation:

Relevant files:

@PascalSenn PascalSenn assigned PascalSenn and unassigned PascalSenn Mar 5, 2020
@PascalSenn PascalSenn added 🎉 enhancement New feature or request 🗣 discussion 📚 documentation This issue is about working on our documentation. and removed 📚 documentation This issue is about working on our documentation. labels Mar 5, 2020
@michaelstaib
Copy link
Member

michaelstaib commented Mar 5, 2020

Old:

public interface IDocumentationProvider
{
    string GetSummary(Type type);
    string GetSummary(MemberInfo member);
    string GetSummary(ParameterInfo parameter);
}

New:

public interface IDocumentationProvider
{
    string GetDescription(Type type);
    string GetDescription(MemberInfo member);
    string GetDescription(ParameterInfo parameter);
}

I think we should refactor the documentation provider. When we talk about documentation in the context of GraphQL we call it description. So we should rename that to GetDescription and GetDescription will extract the description from a .NET type, member, parameter.

With this it is more clear that we actually do not only mean the summary.

We also should add to our interface some documentation and make that clear and also point to the fact that the string that is returned is allowed to use markdown.

Further, I like the proposal of your markdown structure for field documentation lets go ahead with that.

I think refactor the interface and go ahead with your proposal.

@michaelstaib michaelstaib added this to the HC-11.0.0 milestone Mar 5, 2020
@michaelstaib michaelstaib added Hot Chocolate Types 🎨 refactoring This issue is about doing refactoring work, like cleaning up the code making existing code better. labels Mar 5, 2020
@rstaib
Copy link
Member

rstaib commented Mar 6, 2020

Shouldn't we use GraphQL Descriptions for documentation purposes?

"""
My Type ;-)
"""

@John0x
Copy link
Contributor Author

John0x commented Mar 6, 2020

I agree @michaelstaib

Should we only add exceptions to the graphql docs that contain a "code" attribute or just all of them?

@rstaib
You mean directly in the c# code?
The xml docs get converted to graphql descriptions as far as I know. I just copied the examples from the playground schema, that's why they are comments in the examples and not descriptions.

@michaelstaib
Copy link
Member

@John0x I think he means in your example of the sdl.

  """
  Updates the user
   
  **Returns:** User object of the updated user
  
  **Errors:**
  1. USER_NOT_FOUND: Couldn't find user
  2. DB_NOT_NULL_VIOLATION: General database not null violation
  3. DB_UNIQUE_VIOLATION: General database unique violation
  4. DB_UPDATE_EXCEPTION: General database update exception
  """
  updateUser(
    "Email of the user"
    email: String!
    "User DTO"
    input: UpdateUserInput!
  ): User!

since # in graphql are for comments. But you do not need to worry about that since these representations are correctly handled by the schema syntax serializer.

But for consistency we should correct the examples.

@michaelstaib
Copy link
Member

@John0x we should only include the one with a code attribute since the other exceptions could be internal exceptions that you do not want to be exposed over your service layer.

@John0x
Copy link
Contributor Author

John0x commented Mar 6, 2020

Okay :)
I've updated the examples.

Attached is an image of the current status, any suggestions for the formatting or is it okay like that?
Generated from:

        /// <summary>
        /// Creates a review for a given Star Wars episode.
        /// </summary>
        /// <param name="episode">The episode to review.</param>
        /// <param name="review">The review.</param>
        /// <param name="eventSender">The event sending service.</param>
        /// <exception cref="Exception" code="TEST_ERROR">Test exception dude</exception>
        /// <returns>The created review.</returns>

Bildschirmfoto 2020-03-06 um 13 24 05

@michaelstaib
Copy link
Member

looks good so far

@rstaib
Copy link
Member

rstaib commented Mar 6, 2020

looks nice

@rstaib
Copy link
Member

rstaib commented Mar 6, 2020

One remark here regarding the exceptions, shouldn't we use an unordered list instead of an ordered list?

@John0x
Copy link
Contributor Author

John0x commented Mar 6, 2020

@rstaib generally yes, but the Playground doesn't seem to display unordered lists properly

@John0x
Copy link
Contributor Author

John0x commented Mar 6, 2020

Formatting with unordered list:
Bildschirmfoto 2020-03-06 um 15 12 34

@rstaib
Copy link
Member

rstaib commented Mar 6, 2020

@John0x but isn't this a problem inside the tool. The question is whether we should be semantically correct or working fine in a certain tool. Perhaps we should tell them. Have you tested Banana Cake Pop ;-) would be interested whether it's working fine.

@John0x
Copy link
Contributor Author

John0x commented Mar 6, 2020

@rstaib Generally I would agree with you, but the playground is the standard and comes preinstalled so it should at least look decent in there. An unordered list would semantically make more sense but at least for me, it's not too much of a problem if it was an ordered list. We should probably tell them, haven't done so yet though 😄

I'm gonna test it with the banana

@michaelstaib michaelstaib linked a pull request Mar 8, 2020 that will close this issue
michaelstaib added a commit that referenced this issue Mar 8, 2020
… description. (#1524, #1516)

Co-authored-by: Moritz Brandes <mb@grannyandsmith.com>
Co-authored-by: Michael Staib <michael@chillicream.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗣 discussion 🎉 enhancement New feature or request 🎨 refactoring This issue is about doing refactoring work, like cleaning up the code making existing code better.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants