如何配置GatsbyJS火存储插件 时间戳在快照中更改



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

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 插件中实现此更改要求?

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

Github 存储库已更新以避免警报,但维护者尚未更新 npm 上的插件。 我建议一个临时解决方案,直到他这样做。 您可以从 Github 上的主分支安装插件

yarn add taessina/gatsby-source-firestore#master

npm i taessina/gatsby-source-firestore#master

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

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

最新更新