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