I am using gatsby-transformer-json
to query JSON files in Gatsby. There are image URLs within the JSON file, however they are absolute file paths and Gatsby only transforms relative paths into image nodes.
My JSON:
{
"defaultImage": "images/defaultImage.jpg"
}
My query:
metadataJson {
defaultImage {
childImagageSharp {
fixed(width: 3200, height: 2133) {
...GatsbyImageSharpFixed
}
}
}
}
However this fails with an error because Gatsby is encountering the absolute path and because it isn't relative, it doesn't transform it to a Sharp image node.
If it was a Markdown file I could transform the path myself and save it to the Markdown node's fields
object. However that option isn't available to me with gatsby-transformer-json
.
How can I transform the absolute path in a JSON file so that Gatsby will replace the path with a Sharp image node?