gatsby-uc / gatsby-source-strapi

Gatsby source plugin for building websites using Strapi as a data source
MIT License
355 stars 183 forks source link

Issue generating links for nested collection routes #329

Closed alesma closed 1 year ago

alesma commented 2 years ago

Hi,

i have found an issue with generating links for nested collection routes,

in a scenario where a page folder structure is as follows

- pages
--{StrapiEntity.relation__relationKey}
---{StrapiEntity.key}.tsx

the generated pages will be e.g. '/fruit/apple' or '/vegetable/spinach'

according to gatsby docs, to generate the links to collection routes there is a gatsbyPath fn that can be used in queries to generate the URL (https://www.gatsbyjs.com/docs/reference/routing/file-system-route-api/#routing-and-linking)

To generate the links gatsbyPath, the actual relational node data is needed, https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-page-creator/src/derive-path.ts#L42

but gatsby-source-strapi deletes that node in the normalizer and only makes available a __node key with a value set to the relation node id.

https://github.com/strapi/gatsby-source-strapi/blob/master/src/normalize.js#L212

that results in gatsbyPath returning the link as `{StrapiEntity.relation__relationKey}/apple' as the relation data is not defined.

I am wondering why that delete is there? i have deleted that line locally and the links are generated correctly.

moonmeister commented 1 year ago

Thanks for your interest in this project. This plugin is moving into the Gatsby User Collective and this repo will be archived. Please open an issue in that repository, submit a PR if you'd like to see this implemented, or join us on Discord if you have questions!