gatsby-source-strapi icon indicating copy to clipboard operation
gatsby-source-strapi copied to clipboard

Images are not loaded inside relations

Open denisgoryaynov opened this issue 2 years ago • 5 comments

I have a content type called "Product Category" with a one to many relation to itself. A "Product Category" also has a one to many relation with "Product" content type. When dealing with the following tree:

  • Product Category "main"
    • Product Category "sub-main"
      • Product 1
      • Product 2
Screenshot 2022-03-20 at 15 15 41

Images for "Product" are not loaded, I can see the featured_image field inside graphql, but the localFile field is not available so I cannot use gatsby-image with it

I am using Strapi 4.2.0-beta.0 and gatsby-source-strapi 2.0.0-beta.0

Edit: at least in my case adding the following code after this line https://github.com/strapi/gatsby-source-strapi/blob/2a60320b16ae6520617d743158c433d384dbd155/src/download-media-files.js#L126 fixes the issue:

if (type === 'relation' && Array.isArray(value)) {
   for (const element of value) {
      await extractImages(element, ctx, attribute.target);
   }
}

denisgoryaynov avatar Mar 20 '22 14:03 denisgoryaynov

@denisgoryaynov we are not extracting images for relations I guess the best way to do it would be to fetch the relationnal content type so they will be linked together in your gatsby graphiQL. So one side you populate the first level of relation and on the other side you populate the linked relations and the images.

Doing so as a great advantage especially for rebuilds because in Strapi when you update a relation entity it does not change the updated_at field of the linked relations so it won't trigger a rebuild on the Gatsby side as we will still use the cached data.

soupette avatar Mar 22 '22 15:03 soupette

Hi,

Is there any update on this issue? This has been a huge blocker for me and my team.

IanSpringer avatar Jul 26 '22 13:07 IanSpringer

You might be able to use gatsby-plugin-remote-images as a work around. You'd then have to explicitly define the GraphQL types with image urls.

raae avatar Jul 26 '22 15:07 raae

@IanSpringer are you populating the images from you relations?

soupette avatar Jul 26 '22 15:07 soupette

@soupette I have populated the images in my relations, yes. I actually created an issue a few days back about this same thing thinking it was a problem with relations + dynamic zones. See here https://github.com/strapi/gatsby-source-strapi/issues/336

When adding an image to a collection type, and then pulling that collection item as a relation in our dynamic zone, we cannot query localFile on the images. This is a big problem as we rely on gatsby image sharp processing. Without this capability, we will take a big hit in our performance, or run the risk of spending lots of hours on dev time to try and hack a fix.

IanSpringer avatar Jul 26 '22 18:07 IanSpringer

Fix in #344

moonmeister avatar Dec 27 '22 18:12 moonmeister