Skip to content

Instantly share code, notes, and snippets.

@IliasHad
Last active October 5, 2020 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IliasHad/ed1eb18a520540c6453b832acce0265e to your computer and use it in GitHub Desktop.
Save IliasHad/ed1eb18a520540c6453b832acce0265e to your computer and use it in GitHub Desktop.
How to Gatsby Image in Strapi Multiple Image
exports.onCreateNode = async ({
node,
actions,
store,
cache,
createNodeId,
}) => {
const { createNode } = actions
let multipleImages = node.images
if (node.internal.type === "StrapiProducts") {
if (multipleImages.length > 0) {
multipleImages.forEach(el => console.log(el))
const images = await Promise.all(
multipleImages.map(el =>
createRemoteFileNode({
url: `http://localhost:1337/${el.url}`,
parentNodeId: node.id,
store,
cache,
createNode,
createNodeId,
})
)
)
multipleImages.forEach((image, i) => {
image.localFile___NODE = images[i].id
})
}
}
}
@DenisCor
Copy link

DenisCor commented Oct 4, 2020

Cannot query field "localFile" on type "StrapiProductThumbnail"... not working for me... :(

@IliasHad
Copy link
Author

IliasHad commented Oct 5, 2020

@Sakaluke Could you share with me the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment