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

bug(gatsby-source-strapi): Relations are not picked up if they are named "parent" or "children" #339

Open
denisgoryaynov opened this issue Mar 20, 2022 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@denisgoryaynov
Copy link

denisgoryaynov commented Mar 20, 2022

Since "parent" and "children" are reserved keywords in gatsby, this plugin automatically appends "strapi_" to the relation name. Since the relations are now named "strapi_parent" and "strapi_children" the code on this line doesn't work, https://github.com/strapi/gatsby-source-strapi/blob/2a60320b16ae6520617d743158c433d384dbd155/src/download-media-files.js#L117, since the relations on the strapi schema are named just "parent" and "children", but attributeName is "strapi_parent" and "strapi_children".
This problem is related to the other issue I have with relations: gatsby-uc/gatsby-source-strapi#308, because without changing the code to schema.schema.attributes[attributeName.replace('strapi_', '')] the fix I illustrated in the other issue doesn't work because the fields generated from this plugin and the schema on strapi are different

@soupette
Copy link

@denisgoryaynov the parent and children names are forbidden in gatsby this is why we prefixed them with strapi_ same for the id field.

@denisgoryaynov
Copy link
Author

Hi @soupette, I understand that those names are forbidden in gatsby and that's why they are prefixed with strapi_, the problem is that this change is not reflected when getting the data from the strapi schema when downloading images.
Inside this line of code const attribute = schema.schema.attributes[attributeName]; the schema.schema.attributes has the children and parent fields (because it is fetched from the content builder api), but they are accessed using the prefixed fields strapi_children and strapi_parent, thus returning undefined every time

@soupette
Copy link

Hi @soupette, I understand that those names are forbidden in gatsby and that's why they are prefixed with strapi_, the problem is that this change is not reflected when getting the data from the strapi schema when downloading images. Inside this line of code const attribute = schema.schema.attributes[attributeName]; the schema.schema.attributes has the children and parent fields (because it is fetched from the content builder api), but they are accessed using the prefixed fields strapi_children and strapi_parent, thus returning undefined every time

You are right! it's a bug indeed, would you mind opening a PR to fix the issue so we can make a new release?

@moonmeister moonmeister changed the title Relations are not picked up if they are named "parent" or "children" bug(gatsby-source-strapi): Relations are not picked up if they are named "parent" or "children" Dec 27, 2022
@moonmeister moonmeister transferred this issue from gatsby-uc/gatsby-source-strapi Dec 27, 2022
@moonmeister moonmeister added the bug Something isn't working label Dec 27, 2022
@moonmeister moonmeister added the help wanted Extra attention is needed label Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants