Hi there, does anyone have any idea why nodes are not being created?
exports.sourceNodes = async ({
actions,
createNodeId,
createContentDigest
}) => {
const { createNode } = actions
const apiKey = process.env.PLACES_API_KEY
const placeIds = listingsJson.map(n => n.places_id).filter(n => n)
placeIds.map(async placeId => {
await axios
.get("https://maps.googleapis.com/maps/api/place/details/json", {
params: {
key: apiKey,
fields: "name,rating,price_level,website,opening_hours",
placeid: placeId
}
})
.then(response => {
const node = response.data.result
console.log(node)
const jsonNode = JSON.stringify(node)
return createNode({
id: createNodeId(`place-${placeId}`),
parent: null,
field: jsonNode,
children: [],
internal: {
type: "Places",
content: jsonNode,
contentDigest: createContentDigest(node)
}
})
})
})
}
We need to wait for all promises created from placeIds to finish - right now they are not being awaited - please use something like:
-placeIds.map(async placeId => {
+await Promise.all(placeIds.map(async placeId => {
(+ adding closing ) to match one added for Promise.all
Most helpful comment
We need to wait for all promises created from
placeIdsto finish - right now they are not beingawaited - please use something like:(+ adding closing
)to match one added forPromise.all