1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00
market/plugins/gatsby-source-ocean/gatsby-node.js

43 lines
941 B
JavaScript
Raw Normal View History

const axios = require('axios')
exports.sourceNodes = async (
{ actions, createNodeId, createContentDigest },
2020-07-08 15:15:02 +02:00
{ aquariusUri }
) => {
const { createNode } = actions
// Query for all assets to use in creating pages.
const result = await axios(`${aquariusUri}/api/v1/aquarius/assets`)
for (let i = 0; i < result.data.ids.length; i++) {
const did = result.data.ids[i]
const metadataResult = await axios(
`${aquariusUri}/api/v1/aquarius/assets/metadata/${did}`
)
const metadata = {
did,
...metadataResult.data.attributes
}
const nodeMeta = {
id: createNodeId(did),
parent: null,
children: [],
internal: {
type: 'OceanAsset',
contentDigest: createContentDigest(metadata),
2020-07-08 15:15:02 +02:00
description: `All data sets queried from ${aquariusUri}`
}
}
const node = {
...metadata,
...nodeMeta
}
await createNode(node)
}
}