Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为GatsbyJS创建Firestore插件_Gatsby - Fatal编程技术网

为GatsbyJS创建Firestore插件

为GatsbyJS创建Firestore插件,gatsby,Gatsby,我正在尝试为盖茨比创建自己的源插件。在这个特殊的例子中,我尝试创建一个firestore源插件。我知道firestore已经有了源插件,但我想学习如何自己创建源插件,尤其是从数据库创建源插件(我已经在盖茨比网站上浏览了) 话虽如此,但插件不起作用,我不确定问题出在哪里。我已经做了一个console.log,我知道正在为firestore检索数据。此外,在控制台中执行develope操作时也没有错误。该站点构建正确——我可以访问graphiql。但是,数据不会显示在graphiql中 下面是插件中

我正在尝试为盖茨比创建自己的源插件。在这个特殊的例子中,我尝试创建一个firestore源插件。我知道firestore已经有了源插件,但我想学习如何自己创建源插件,尤其是从数据库创建源插件(我已经在盖茨比网站上浏览了)

话虽如此,但插件不起作用,我不确定问题出在哪里。我已经做了一个console.log,我知道正在为firestore检索数据。此外,在控制台中执行
develope
操作时也没有错误。该站点构建正确——我可以访问
graphiql
。但是,数据不会显示在graphiql中

下面是插件中的
gatsby node.js
文件:

const firebase = require("firebase-admin")
const firebaseCert = require("./firebase-adminsdk.json")

exports.sourceNodes = async ({
  actions,
  createNodeId,
  createContentDigest,
}) => {
  try {
    if (firebase.apps || !firebase.apps.length) {
      firebase.initializeApp({
        credential: firebase.credential.cert(firebaseCert),
      })
    }
  } catch (e) {
    report.warn("Could not initialize Firebase. Please check credentials")
    report.warn(e)
    return
  }

  const { createNode } = actions

  const db = firebase.firestore()

  db.collection("newsFeed")
    .get()
    .then(snapshot => {
      snapshot.docs.forEach(doc => {
        createNode({
          id: createNodeId(`feedly-feed-${doc.id}`),
          parent: null,
          children: [],
          internal: {
            type: `FeedlyFeeds`,
            content: JSON.stringify(doc.data()),
            contentDigest: createContentDigest(JSON.stringify(doc.data())),
          },
        })
      })
    })
}

知道这为什么不起作用吗?我能做些什么使它起作用?

尝试同步创建节点或返回承诺。尝试同步创建节点或返回承诺。