-
Notifications
You must be signed in to change notification settings - Fork 183
Gatsby not generating childimagesharp nodes for image fields inside components #98
Comments
I am having a similar problem. Images inside dynamic zone components does not generate childimagesharp nodes. In the following query strapiPage is a content type. Inside content there are dynamic zone components.
A workaround is adding this to your gatsby-node.js:
|
Hello @secretlifeof , that's very useful. I'll try that next. I've been trying to learn how to do custom functions in gatsby-node, but it's hard to wrap your head around, haha. I've been having another related headache - when I have multiple image components within a dynamic zone, their image data gets scrambled. I can pull in all the related component fields like the image descriptions just fine, but the image file data gets mixed up so the pictures get put in the wrong places. I'm not sure how to fix that either. Edit: got around to trying out using a custom resolver as you said. It seems to work! Thanks so much. |
The site I'm working on has many components with images that don't return childImageSharp nodes when querying Strapi. Here is one example query: const data = useStaticQuery(graphql`
query innovationLabArticleQueryData {
content: strapiInnovationLab {
articles {
header {
subtitle
title
}
sections {
image {
childImageSharp {
fluid(maxWidth: 550, maxHeight: 340, quality: 100) {
...GatsbyImageSharpFluid_withWebp
presentationWidth
presentationHeight
}
}
}
title
body
}
}
}
}
`); And the error for this one:
So I've added the following to gatsby-node.js, but I still see the same error (I ran gatsby clean as well). // To resolve childImageSharp issue: https://github.com/strapi/gatsby-source-strapi/issues/98
exports.createResolvers = ({
actions,
cache,
createNodeId,
createResolvers,
store,
reporter,
}) => {
const { createNode } = actions
createResolvers({
StrapiInnovationLabArticlesSectionsImage: {
imageFile: {
type: `File`,
resolve(source, args, context, info) {
return createRemoteFileNode({
url: `http://localhost:1337${source.url}`, // `${source.url}` for S3 upload. For local: `http://localhost:1337${source.url}`,
store,
cache,
createNode,
createNodeId,
reporter,
})
},
},
},
})
} Using gatsby-source-strapi v0.0.12 (latest). |
The example in this comment is actually very resourceful in helping me, after some syntax adjustments, I successfully get the childImageSharp.
In your query, sections {
image {
childImageSharp {
fluid(maxWidth: 550, maxHeight: 340, quality: 100) {
...GatsbyImageSharpFluid_withWebp
}
}
} Under |
@benedictjohannes Thanks for posting the clarification. #98 (comment) didn't reference |
@nathany So far, looking at how the plugin resolve fields, it's not easy to implement automated recognition of type of fields in GraphQL query. |
Thanks for your help @secretlifeof ! Your solution works almost perfectly for me but I've noticed that if urls have spaces in them e.g I'm using https://github.com/AHgPuK/strapi-mongodb-files to store my images in MongoDB but I don't think it's a problem with storing the images as I can retrieve them using the url just fine if I manually access it using the browser e.g Has anyone else dealt with this issue? Any help is greatly appreciated! |
Another approach would be defining a just
or directly in your query
I just tested out and it worked for me. I'm new to Gatsby and Strapi, but looking at how Strapi is creating the Types, I think it's easier to add the |
Have the same issues!!! FMPOV plugin is too raw for production usage with |
Although both #98 resolver and #98 Types work well for a single Media, I can't get them to work with Strapi's MultipleMedia, any ideas? |
See title. I made a component with a media field (single) and several enums for image options. But when I do my gatsby build, there's no sharp node being generated. However, if I have a straight up media field right under the content type, then it generates sharp nodes just as you'd expect.
The text was updated successfully, but these errors were encountered: