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

Automatically Update Talawa-Docs with the latest API Schema #1240

Closed
palisadoes opened this issue Mar 31, 2023 · 20 comments · Fixed by #1282
Closed

Automatically Update Talawa-Docs with the latest API Schema #1240

palisadoes opened this issue Mar 31, 2023 · 20 comments · Fixed by #1282
Assignees
Labels
feature request unapproved Unapproved for Pull Request

Comments

@palisadoes
Copy link
Contributor

palisadoes commented Mar 31, 2023

Is your feature request related to a problem? Please describe.
The API GraphQL schema is constantly changing and it is difficult to manually document it for all the developers who need to use it in the following repos:

  1. Talawa
  2. Talawa-API
  3. Talawa-Admin

Describe the solution you'd like
We have identified an open source project that can convert schema files, or query a GraphQL url, to generate a markdown file containing all the elements of the schema using whatever comments the developers have added to the schema definitions.

We would like to:

  1. use this software to automatically add the latest schema to the appropriate file in Talawa Docs with every post PR push
  2. keep the generator code within the Talawa-API repo in a directory tree reserved for GitHub automation (if advisable)

Describe alternatives you've considered

N/A

Approach to be followed (optional)

See above

Additional context

  1. The https://github.com/exogen/graphql-markdown installation is incorrect.
  2. The build process creates a src/index.js file which the documentation refers to as the graphql-markdown executable.
@github-actions github-actions bot added the unapproved Unapproved for Pull Request label Mar 31, 2023
@palisadoes
Copy link
Contributor Author

@tasneemkoushar, @anwersayeed and @evasharma12 this should be interesting to you.

@EshaanAgg
Copy link
Contributor

I would like to work on this issue @palisadoes.

@anwersayeed
Copy link
Contributor

I would like to work on this issue @palisadoes.

SpectaQL, you may try this library too.

@palisadoes
Copy link
Contributor Author

@EshaanAgg

You may want to work on this one simultaneously

@palisadoes
Copy link
Contributor Author

I would like to work on this issue @palisadoes.

SpectaQL, you may try this library too.

This format looks better.

@EshaanAgg try both and let us know which one you think gives a more readable output

@EshaanAgg
Copy link
Contributor

@palisadoes @anwersayeed
The problem that I am facing while using both of the tools is that they need the .graphql file of the schema to generate the documentation automatically.

They can do the same themselves, but with some caveats:

  1. We can provide them with the URL of the hosted API service, and then they would use Introspection queries to generate the same. The same is not possible for us as we do not host the API anywhere.
  2. We can provide them with the schema in .json or .gql files, but the same isn't generated by us as of now(or I am not aware of the same). Thus even this option goes out of the window for us.

If someone with some prior experience can help me in the same, I would greatly appreciate it.

@EshaanAgg
Copy link
Contributor

@palisadoes
Can we consider hosting the API online? That way we can directly make a cron job in the Talawa-Docs repository to fetch the GraphQL schema from the hosted API, and update the same if any schema definitions have changed.
We have a hosted API URL linked to the repository, but I don't think so the same is functional any more.

@anshgoyalevil
Copy link
Contributor

@palisadoes @EshaanAgg

We would be integrating Squash CI, which would orchestrate a development server with each PR, and thus we can generate the Schema using that server's link

@palisadoes
Copy link
Contributor Author

Can this be used with a simplified installation process for GitHub?

@anshgoyalevil
Copy link
Contributor

@palisadoes

I guess this can be used too. @EshaanAgg Check out this supercharge/mongodb-github-action#24 if you face any error while connecting to URL.

@EshaanAgg
Copy link
Contributor

EshaanAgg commented Apr 3, 2023

@palisadoes @anshgoyalevil
The problem isn't starting a MongoDB container, it's running the server and executing the Markdown Generator script parallely. Because after we run the 'npm run dev' command, the terminal would be engaged in the same process.

One prospective way of doing so may be using a docker image and exposing a development container via the same in the GitHub action.

@anshgoyalevil
Copy link
Contributor

@EshaanAgg I think we can run npm run dev command in detached mode with a workaround in linux. Moreover, having a docker image is always a good idea for a multi-repo based application, but that would then include creating the docker images everytime a PR is created, then instantiating a container. Shouldn't we use other CI tools for all that, like Jenkins.

@palisadoes
Copy link
Contributor Author

GitHub actions allows you to create jobs in which you can make one job dependent on another. We had that before for the API workflow:

Docker example:

We have a limited number of minutes (2000) per month for GitHub actions. Ideally we will want to do this on the push when the PR is merged.

@palisadoes
Copy link
Contributor Author

palisadoes commented Apr 4, 2023

@EshaanAgg @anwersayeed Which one do you think we should go with?

  1. SpectaQL:
    1. is much more visually appealing and usable, though it outputs as HTML versus markdown.
    2. It uses frames so that the menu items on the left are always visible.
    3. It allows you to have a custom introduction at the top of the page obtained from a pre-defined markdown file.
    4. Has its own CSS. We'll need to find a way to override it for Talawa-Docs
    5. Has an embeddable mode where only the body HTML is generated, but the specific stylesheets are still created.
  2. GraphQL Markdown:
    1. Will blend in better with our Docusaurus site as it doesn't have any custom CSS
    2. Doesn't have the customizations
    3. Allows you to have a custom introduction at the top of the page too.

SpectaQL

image

GraphQL Markdown

image

@palisadoes
Copy link
Contributor Author

I've been playing around with this. If you put the SpectaQL output in an HTML iframe the rendering of the query strings becomes a single line of text that scrolls off the page versus what we see in the black sections above.

Let's stick with the Markdown solution, then we can figure out SpectaQL later.

@EshaanAgg
Copy link
Contributor

I also advocate for GraphQL Markdown because of its simplicity and the fact that it generates a simple markdown file. It would be much easier to configure the same into Talawa Docs than a complete HTML file! SpectaQL has a nice look and feel, but introduces overhead that I don't think so we need right now.

@xoldd
Copy link
Contributor

xoldd commented Apr 4, 2023

@palisadoes @EshaanAgg @anshgoyalevil This one's good too:-
https://magidoc.js.org/introduction/welcome

Graphql markdown looks good too.

@anshgoyalevil
Copy link
Contributor

@xoldyckk

I checked Magidoc. The features like Example Query, Sidebar, etc looks good.

For it to work, custom scalers would need to be configured with queryGenerationFactories which could increase the implementation complexity.

@EshaanAgg
Copy link
Contributor

I agree with @anshgoyalevil. While the look and feel of Magidoc is great, I feel it would be much easier to integrate GraphQL Markdown into both the workflows and Talawa Docs.

@palisadoes
Copy link
Contributor Author

palisadoes commented Apr 4, 2023

I just discovered this:

It automatically creates the required menu entries for each. Look at this:

This looks like exactly what we need.

palisadoes pushed a commit that referenced this issue Apr 11, 2023
… (#1247)

* Add schema documentation

* Add branch for testing

* Fix docker action

* Fix script

* Remove docker

* Bug fix

* Move to correct workflow file

* Remove docker files

* Add documentation and change directory structure

* Add schema export

* Fix linting

* Make required changes

* Linting fix

* Change commit message

* Add docs directory

* Add manual git command

* Disable hooks in CI

* Generate GraphQL Schema and Markdown Documentation

* Better descriptions

* Add docs to ESLint ignore

* Upload schema.json as artifact

* Sync

* Fix movement

* Bug fix

* Syntax fix

* Syntax fix

* Bug fix

* Add ls

* Add ls

* Change driectories

* Add listing

* Fix directory structure

* Change branchname

* Remove spec

* Fix workflow

* Generate GraphQL Schema and Markdown Documentation

* Add secret authentication

* Finalise tested workflow

* Change token

* Move get-graphql-schema to a dev dependency

* Move to TALAWA_DOCS_SYNC token

---------

Co-authored-by: EshaanAgg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request unapproved Unapproved for Pull Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants