如何配置GatsbyJS firestore插件re。 timestampsInSnapshots更改

时间:2018-09-04 07:51:16

标签: google-cloud-firestore gatsby

我已经安装并配置了gatsby-source-firestore插件。 当我运行“ gatsby开发”时,该应用会启动。 但是,在终端中,出现以下警告:

The behavior for Date objects stored in Firestore is going to change
AND YOUR APP MAY BREAK.
To hide this warning and ensure your app does not break, you need to 
add the following code to your app before calling any other Cloud 
Firestore methods:

  const firestore = new Firestore();
  const settings = {/* your settings... */ timestampsInSnapshots: 
  true};
  firestore.settings(settings);

With this change, timestamps stored in Cloud Firestore will be read 
back as Firebase Timestamp objects instead of as system Date objects. 
So you will also need to update code expecting a Date to instead 
expect a Timestamp...

问题是:如何在我的firestore gatsby插件中实现此更改要求?

1 个答案:

答案 0 :(得分:0)

这是在插件级别处理的。 Github上的以下位置也提到了此行为:https://github.com/taessina/gatsby-source-firestore/issues/12

Github存储库已更新,可以避免出现警报,但维护人员尚未在npm上更新插件。 我建议临时解决方案,直到他这样做为止。 您可以通过以下方式从Github上的master分支安装插件:

yarn add taessina/gatsby-source-firestore#master

npm i taessina/gatsby-source-firestore#master

确保正确处理时间戳记。我的gatsby配置看起来像这样:

    {
      resolve: 'gatsby-source-firestore',
      options: {
        credential: firestoreCredential,
        types: [
          {
            type: 'FirestoreEvent',
            collection: 'events',
            map: ({
              timeStart,
            }) => ({
              timeStart: timeStart.toDate(),
            }),
          },
        ],
      },
    },