有时在gatsby-node中附加文件节点时没有相应的节点

时间:2019-07-19 15:21:17

标签: gatsby

在gatsby节点中,我在onCreateNode中创建了一个新的remoteFile节点,并尝试将其添加到创建的节点中。有时它会建立,有时却不会。

这是我的gatsby节点文件

exports.onCreateNode = async ({ node, getNode, actions, cache, store, _auth, createNodeId }) => {
  const { createNodeField, createNode } = actions
  if (node.internal.type === `nodeTypeForImage`) {

    // maybe create node
    if (node.imageUrl) {
      fileNodePromise = createRemoteFileNode({
        url: node.imageUrl,
        parentNodeId: node.id,
        store, cache, createNode, createNodeId, auth: _auth,
      })
    } else {
      fileNodePromise = Promise.resolve(null)
    }

    // add field with remoteFile if possible
    return fileNodePromise
      .then(fileNode => {
        if (fileNode) {
          console.log(fileNode) 
          node.localFile___NODE = fileNode.id
        }
  } else {
    return Promise.resolve()
  }
}

以下是我有时会收到的错误。也许是因为网址返回了404左右?运行一次或两次,更改文件,然后还原更改,所有这些都有助于使构建成功。我不明白为什么或如何解决它。

Encountered an error trying to infer a GraphQL type for: 
`localFile___NODE`. There is no corresponding node with the `id` field 
matching: "6996792c-be0e-573f-b175-52fa02c1f99c".

更新:关键问题可能是在onCreateNode中此行是否正确:

node.localFile___NODE = fileNode.id

0 个答案:

没有答案