Skip to content

[Docs] Schema-based Reference Generation #3048

Closed

Description

@crjm

We should implement schema-based API reference generation.

Will add more info as I research more.

Examples:

Activity

  1. self-assigned this
    on Aug 24, 2022
  2. added this to the Cloak GA milestone on Sep 16, 2022
  3. transferred this issue fromdagger/cloakon Sep 16, 2022
  4. vikram-dagger commented on Sep 19, 2022

    @vikram-dagger
    Contributor

    I investigated the following options:

    All 3 tools had difficulty generating API docs from our GQL schema files, due to numerous linter errors (see #3136). However as they all support introspection, I was able to auto-generate API docs from the cloak dev server itself.

    See examples of the auto-generated API output at https://vikram-dagger.github.io/.

    Summary of results:

    • The first two tools generate markdown and a sidebar, so can be immediately integrated with Docusaurus. SpectaQL generates HTML, so can be integrated only as a separate set of static pages. This also means it does not automatically inherit the current doc site's CSS, it needs to be manually set up to match the existing doc site's layout and CSS. Alternatively, we would need to run a second process to convert the HTML to markdown, after which the files can be treated like other Docusaurus content.
    • The first tool produces output in a hardcoded output directory, so the files need to be manually moved to the correct location. The other two tools don't have this issue.
    • SpectaQL docs, by virtue of being separate HTML pages, always open in a new tab as this is the Docusaurus default behaviour.
    • All three tools generate unified reference docs ie. core and extension APIs are merged in the output docs. This is because they use the GraphQL introspection API. If we wish to show our core and extension APIs separately in the navigation tree (which IMO is preferable), we would need to instead use the schema files as source, writing a script that runs the docs generator once for each schema and then move each set of generated files to the correct location in the Docusaurus filesystem.

    Recommendation:
    Simply because it seems to require the least work to connect with the existing Docusaurus site and the output seems reasonable, I suggest using the second option https://www.npmjs.com/package/@edno/docusaurus2-graphql-doc-generator. However, before deciding, I recommend looking at the navigation structure, layout and content of the generated API docs for all three examples to see if one of them is significantly better than the others.

    Next steps:

    • Decide which generator to use
    • Decide on merged or separate core/extension API docs
    • Fix linter errors in GraphQL schema files
  5. crjm commented on Sep 28, 2022

    @crjm
    ContributorAuthor

    Thanks for taking care of this @vikram-dagger, both for the work and the summary of each alternative. 🙏
    I really did not have enough time to dig into this, but I agree the second option is the best one based on your insights.

  6. added
    area/documentation
    on Sep 28, 2022
  7. vikram-dagger commented on Sep 28, 2022

    @vikram-dagger
    Contributor

    First cut of auto-generated docs included in #3160

  8. jpadams commented on Sep 28, 2022

    @jpadams
    Contributor

    Nice work! 🎉

    Going through it, the "queries" are not really useful it seems:

    Image

    since a working { alpine } query needs more.

    Image

    We list that in the Objects section, but it's not a proper query either...it's showing the schema:

    extend type Query {
      alpine: Alpine!
    }
    
    type Alpine {
      build(pkgs: [String!]): Filesystem!
    }
    

    Image

    Users need this query to do useful work:

    Image

  9. vikram-dagger commented on Oct 1, 2022

    @vikram-dagger
    Contributor

    I'm not very sure how to correct this since the output is based on the schema obtained from introspection - for auto-generated docs, we would probably need to find a way to represent this in the schema itself so it gets reflected in the output docs. Maybe add an example in the schema? Separately, I have checked and it's possible to exclude some sections (eg. queries) from being generated.

  10. crjm commented on Oct 3, 2022

    @crjm
    ContributorAuthor

    I think comments are used to generate text for GraphiQL docs, but I don't think they are the most suitable solution in this case.

  11. mircubed commented on Nov 3, 2022

    @mircubed
    Contributor

    @vikram-dagger can I close this since we are using #3668 to make a decision?

  12. vikram-dagger commented on Nov 4, 2022

    @vikram-dagger
    Contributor

    I think we should leave it open as this may come up again for the GraphQL launch

  13. crjm commented on Nov 8, 2022

    @crjm
    ContributorAuthor

    Reviving this one, currently working on it.

  14. self-assigned this
    on Nov 8, 2022
  15. crjm commented on Nov 8, 2022

    @crjm
    ContributorAuthor

    The upside of using the Docusaurus plugins is that we get the same style and website for both the API and the SDK docs. However, both plugins are short on content quality, as they only reproduce the schema in markdown files.

    spectaql on the other hand, doesn't have Docusaurus as a limitation (it's not forced to output .md files). This makes spectaql a better choice for content quality, but at the same time it breaks with having the API docs and SDK docs in the same docs site.

    From a user standpoint, rich and ready-to-use content is more valuable than CSS styling and one docs site to tackle all documentation, so my thinking is: let's dig more into spectaql which allows more fine-grained customization on the output and then we'll see how to best integrate it into docs.dagger.io. I think that, for now, having a title with the same hierarchy as the rest of the SDKs in the docs and making it a link to api.docs.dagger.io, is the best choice.

    This is still open for discussion though. Will come back with updates on the different possibilities around spectaql.

  16. marcosnils commented on Nov 9, 2022

    @marcosnils
    Contributor

    spectaqlar (cuack 🦆) analysis Juli. Looking forward to this 👐

  17. mircubed commented on Nov 14, 2022

    @mircubed
    Contributor

    @crjm can you provide a summary here, so @shykes knows what to review/approve? I want to make sure that we don't get stuck on last minute feedback.

  18. crjm commented on Nov 14, 2022

    @crjm
    ContributorAuthor

    This is the reference in it's current state
    In summary, we have an API reference generated from the schema files that live in core/schema using spectaql instead of Docusaurus. This reference has examples for each query and, possibly, a link to an execution of that query in the Playground. (design still needs refinement)
    The main reason we didn't choose Docusaurus is basically time. The Docusaurus plugins that generate schema-based documentation did not allow enough customization (cannot provide examples, etc), while spectaql did.
    However, there's a better approach, but more time-consuming: a custom Docusaurus plugin (injects data into Docusaurus). This way the API reference would live inside the Docusaurus SPA and share styles with the documentation. If the GraphQL release date gets pushed, I might have enough time to make it. It's a question of tradeoffs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/documentation

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions