Last active
October 5, 2020 20:20
-
-
Save IliasHad/ed1eb18a520540c6453b832acce0265e to your computer and use it in GitHub Desktop.
How to Gatsby Image in Strapi Multiple Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}) | |
} | |
} | |
} |
@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
Cannot query field "localFile" on type "StrapiProductThumbnail"... not working for me... :(