I have a collection of works that are available through a Strapi API endpoint. Each work has an array containing multiple images. I would like to render them using gatsby-image but I don't have any idea how to do it since all available examples on docs are made with single files or static files on the "images" folder.
When trying the GraphiQL explorer I realized the thumbnail image has this value on 'id' key:
"thumbnail": {
"id": "e:/wamp/www/@flaex_/app/.cache/gatsby-source-filesystem/52e3542d00600c96e52cb584e83c2cae.jpg absPath of file"}
Meaning that the image had been registered on gatsby cache. On the other side the 'id' key on each image of the array show this:
"images": [
{
"id": "5d0d7429fe6de132d43a44b4",
"url": "/uploads/01d8a893fe4c46738b1c99624d22154d.jpg"
},
{
"id": "5d0d7429fe6de132d43a44b3",
"url": "/uploads/eb399dfadea74b9db39672a1f98575ff.jpg"
}
]
Is there something I'm missing here?
This is the template I'm using:
import React from "react"
import { graphql } from "gatsby"
import Img from "gatsby-image"
import Layout from "../components/layout"
import containerStyles from "../pages/portfolio.module.less"
const WorkTemplate = ({ data }) => (
<Layout>
<div className={containerStyles.navsec}>
<button onClick={() => window.history.back()}><< back</button>
</div>
<article>
<h1>{data.strapiWork.title}</h1>
<Img fluid={data.strapiWork.thumbnail.childImageSharp.fluid} />
<p>{data.strapiWork.description}</p>
{console.log(data.strapiWork.images)}
<ul className={containerStyles.works}>
{data.allStrapiWork.images.map(document => (
<li key={document.id}>
<Img fluid={document.image.childImageSharp.fluid} />
</li>
))}
</ul>
</article>
</Layout>
)
export default WorkTemplate
export const query = graphql`
query WorkTemplate($id: String!) {
strapiWork(id: { eq: $id }) {
id
title
description
images {
childImageSharp {
fluid(maxWidth: 120) {
...GatsbyImageSharpFluid
}
}
}
thumbnail {
childImageSharp {
fluid(maxWidth: 500) {
...GatsbyImageSharpFluid
}
}
}
}
}
`
I presume this is not working because 'images' is an array.
The thumbnail image is rendering fine, as it can be seen I tried to replicate the graphQL query used on the thumbnail image but I'm getting this message on the console when running gatsby develop
:
error GraphQL Error Encountered 1 error(s): - Unknown field 'childImageSharp' on type '[StrapiWorkImages]'.
I would appreciate any help in this regard. Thank you!
<Img fluid={document.fluid}/>
- Intellidroiddata
so we can see the structure that is returned? - IntellidroidchildImageSharp
is the issue here but I don't know what structure is returned byStrapiWorkImages
- Intellidroidgatsby-image
plugin? - Intellidroid