zhouzi / docusaurus-graphql-plugin

Docusaurus plugin generating Markdown documentation from a GraphQL schema.
https://gabinaureche.com/docusaurus-graphql-plugin/
24 stars 9 forks source link

Generated Links Break with Docusaurus Internalization #19

Open TS-Daniel16 opened 1 year ago

TS-Daniel16 commented 1 year ago

We tried setting up our project which is using the i18n capabilities of docusaurus (https://docusaurus.io/docs/i18n/introduction) with your graphql plugin, but unfortunately the generated links between markdown files (e.g. from mutations to scalars or objects pages) are broken for non-default languages, because of the added language code in the URL path.

Is there are reason that the paths are the "absolute" paths in the generated md (e.g. /baseUrl/docs/api/objects) or would it be possible to use relative paths (/objects if the /docs/api/ path is the routeBasePath) instead?

I tried changing that part in the index.ts (https://github.com/zhouzi/docusaurus-graphql-plugin/blob/f89c6c84932802b8075af874c8911839c1ebf0a0/packages/docusaurus-graphql-plugin/src/index.ts#L96-L98) that it does not add the baseURL and it solved the language dependent navigation path problem in my project, but not sure if it breaks other things in your plugin.

Happy to provide also a PR enabling relative paths as an additional options property, that existing scenarios would not be forced to adjust.

zhouzi commented 1 year ago

Thanks for reporting, adding support for i18n would be great 👍

As far as I remember I had two issues with relative links:

Honestly both issues are probably easy to fix anyway. If you can submit a PR I am happy to review and run some tests. We can replace the absolute links with relative.

zhouzi commented 1 year ago

This is now fixed as of v0.9.0. Thanks again for contributing @TS-Daniel16 🙌

BowlingX commented 1 year ago

This change breaks links to other categories now. (ending up in a Page not found error) e.g. when a Scalar is linked from the Objects section.

zhouzi commented 1 year ago

Thanks for reporting @BowlingX 🙏 I'll have a look, add a test, push a fix and ping you when it's done 👌

zhouzi commented 1 year ago

@BowlingX sorry for the delay. I've been looking into this issue but not sure how to actually reproduce it. For example it's working fine in the demo:

https://github.com/zhouzi/docusaurus-graphql-plugin/assets/2291025/86dc35bc-dc50-4d62-b654-7dfc914c4ffa

I imagine it's no working under specific conditions but don't know which exactly.

Is your documentation public so I can access it?

Is there anything special in terms of configuration that you think could have an impact?

taipignas commented 4 months ago

@zhouzi, are you using docusaurus version 2.0.0-beta.0? since the pull request made a change of the url straight to getRelativeTypeUrl(type) i dont see how this could work properly when original was joinURL(context.baseUrl, options.routeBasePath, getRelativeTypeUrl(type))

zhouzi commented 4 months ago

@zhouzi, are you using docusaurus version 2.0.0-beta.0? since the pull request made a change of the url straight to getRelativeTypeUrl(type) i dont see how this could work properly when original was joinURL(context.baseUrl, options.routeBasePath, getRelativeTypeUrl(type))

I have not tested it with the latest version of docusaurus, it is very likely that this plugin needs to be updated. I am reopening the ticket 👍