How to configure GatsbyJS firestore plugin re. timestampsInSnapshots change - google-cloud-firestore

I have installed and configured the gatsby-source-firestore plugin.
When I run 'gatsby develop', the app launches.
In the terminal however, the following warning appears:
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...
The question is: how do I implement this change requirement into my firestore gatsby plugin?

This is handled at a plugin level.
This behavior is also mentioned on Github here: https://github.com/taessina/gatsby-source-firestore/issues/12
The Github repo has been updated to avoid the alert but the maintainer hasn't updated the plugin on npm.
I suggested a temporary solution until he does.
You can install the plugin from the master branch on Github with
yarn add taessina/gatsby-source-firestore#master
or
npm i taessina/gatsby-source-firestore#master
Make sure to handle timestamps properly. My gatsby config looks something like that:
{
resolve: 'gatsby-source-firestore',
options: {
credential: firestoreCredential,
types: [
{
type: 'FirestoreEvent',
collection: 'events',
map: ({
timeStart,
}) => ({
timeStart: timeStart.toDate(),
}),
},
],
},
},

Related

Wagtail 3.x postgres search returns no results

I recently updated from Wagtail 2.13.5 to 3.0.3. After the update, the search() method on Wagtail's PageQuerySet returns no results for search terms that clearly should return results (and which do when using the older version).
For example, under 2.13, where search_backend is an instance of wagtail.contrib.postgres_search.backend.PostgresSearchBackend, and qs is an instance of wagtail.core.query.PageQuerySet the following returns lots of results:
search_backend.search('popular-search-term', qs, fields=None, operator=None, order_by_relevance=True, partial_match=True)
But under 3.0.3, where search_backend is now an instance of wagtail.search.backends.database.postgres.postgres.PostgresSearchBackend and qs is an instance of wagtail.query.PageQuerySet, the same call to search() will return nothing (an empty queryset).
The data in the qs queryset is the same in both cases, so maybe I'm missing something in my configuration of the search backend? My "settings.py" file has:
WAGTAILSEARCH_BACKENDS = {
'default': {
'BACKEND': 'wagtail.search.backends.database',
'SEARCH_CONFIG': 'english',
},
}
and
INSTALLED_APPS = [
...
'wagtail.search',
'wagtail.search.backends.database.postgres',
...
]
I had to guess at the value for 'wagtail.search.backends.database.postgres'. AFAICT, Wagtail's docs don't mention what should go into INSTALLED_APPS. But the pre-upgrade value of 'wagtail.contrib.postgres_search' would clearly be wrong, as that module has been removed.
Anyone got an idea why calling search() on a PageQuerySet would incorrectly return no results?
The steps for changing the search backend are documented at https://docs.wagtail.org/en/stable/releases/2.15.html#database-search-backends-replaced. In particular:
You should remove wagtail.contrib.postgres_search from INSTALLED_APPS, and do not need to add anything in its place - the existing wagtail.search app is sufficient
After changing over, you need to re-run the ./manage.py update_index command to ensure that the new search index is populated.

Flutter - Parse Server SDK - IncludeObject not working with liveQuery

I was trying out includeObject method with my livequery in one of my project. I am using Parse_Server_Sdk for this back4App database. Also, I am using flutter parse_server_sdk latest version 1.0.26.
What i want is i have a list of events. So whenever a new event is added in my database then it should trigger the subscription method. I have used following code and it works as well. But, only thing i have issue with is i don't get the includedobject i have added in QueryBuilder.
QueryBuilder<ParseObject> parseQuery =
QueryBuilder<ParseObject>(ParseObject(tblEvents))
..whereEqualTo(tblEventUserId, currentUser);
parseQuery.includeObject([tblOrganizerId]);
Subscription subscription = await liveQuery.client.subscribe(parseQuery);
subscription.on(LiveQueryEvent.create, (value) {
print("val : ${value}");
print("val : ${value.runtimeType}");
});
Output :
val : {"className":"Group_Events","objectId":"uotQ6BpT4C","createdAt":"2020-08-27T07:18:26.581Z","updatedAt":"2020-08-27T07:18:26.581Z","organizer_id":{"__type":"Pointer","className":"Organizer","objectId":"t9M1oyZHh4"},"user_id":{"__type":"Pointer","className":"_User","objectId":"Hx5xJ5ABxG"},"weight":1}
I/flutter (30335): val : ParseObject
I have also evaluated the expression. But, there is only limited pointer data to "tblOrganizerId". I am not getting whole data of that table.
Can anyone suggest me a workaround or a solution?
Thanks.
I would use the "ParseLiveListWidget". It should be perfect for this scenario.
You can find an example here.
Additional information is in this README.
(Use version 1.0.27 for some important bug fixes.)

SAP UIveri5 Minimum example

I am trying to understand how UIveri5 works and how to apply it to my own projects, but due to the minimal documentation I am unable to create a minimal working example.
I tried to apply the code from https://github.com/SAP/ui5-uiveri5/blob/master/README.md to "my" minimal app ( https://ui5.sap.com/1.62.0/#/sample/sap.m.sample.Button/code/ ), but the IDE VS Code marks errors, since i.e. the commands export or define are not known and I don't see where UIveri5 loads them from. Also if I just execute uiveri5 in my command line as is, I am getting an error ( I guess from selenium ) that my Chrome binary is missing, but don't the drivers get downloaded automatically?
conf.js
exports.config = {
profile: 'integration',
baseUrl: 'localhost:8080/.../sap.m.sample.Button',
};
page.spec.js
describe('Page', function () {
it('should display the page',function() {
element(by.control({
viewName: 'sap.m.sample.Button.Page',
controlType: 'sap.m.Page',
properties: {
title: "Page"
}}));
});
});
It would be awesome if someone already build a minimal example and can share it. It would help me very much in understanding how everything works together.
The minimum example is right in the readme.md. The only problem I see here is with the baseUrl - this should be a valid URL to an existing app. If this is a sample app on your localhost, you need a dev server.

Firestore + Cloud Functions: Date behavior has changed, YOUR APP MAY BREAK [duplicate]

Yesterday, all my firebase functions started throwing the following warning:
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. For example:
// Old: const date = snapshot.get('created_at');
// New: const timestamp = snapshot.get('created_at'); const date =
timestamp.toDate();
Please audit all existing usages of Date when you enable the new
behavior. In a future release, the behavior will change to the new
behavior, so if you do not follow these steps, YOUR APP MAY BREAK.
Now I want to init my firestore correctly according to this warning. i'm using typescript.
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp(functions.config().firebase);
let fireStoreDB = fireStoreDB || admin.firestore()
the firestore() that return from admin doesn't have a .settings() method as described in the warning nor it gets an object in the constructor. (It gets an App Object).
so I have two questions:
How can init my firestore to get the settings object?
when I insert a date to a document or when I query a document do I also need to pass the Firestore.Timestamp object? or can i query/insert the normal JS Date object and it will get converted automatically?
Thanks.
EDIT:
i managed to solve it for http functions using :
if (!fireStoreDB){
fireStoreDB = admin.firestore();
fireStoreDB.settings(settings);
}
But it still is happening on firestore triggers.
anyone knows how to give default settings to admin on :
admin.initializeApp(functions.config().firebase);
so it will not happen on firestore triggers?
You are still receiving JS Date instead of Firestore Timestamp due to a bug... now fixed in Firebase Functions v2.0.2.
See: https://github.com/firebase/firebase-functions/releases/tag/v2.0.2.
For initialisation I've used admin.firestore().settings({timestampsInSnapshots: true}) as specified in warning message, so the warning has disappeared.
When you add a date to a Document, or use as a query parameter, you can use the normal JS Date object.
add below 2nd line code in your index.js firebase functions file
admin.initializeApp(functions.config().firebase);
admin.firestore().settings( { timestampsInSnapshots: true })
solved it the following way:
const settings = {timestampsInSnapshots: true};
if (!fireStoreDB){
fireStoreDB = admin.firestore();
fireStoreDB.settings(settings);
}
For firebase-admin version 7.0.0 or above
You should not be getting this error anymore.
In Version 7.0.0 - January 31, 2019 of firebase-admin there were some breaking changes introduced:
BREAKING: The timestampsInSnapshots default has changed to true.
The timestampsInSnapshots setting is now enabled by default so timestamp
fields read from a DocumentSnapshot will be returned as Timestamp objects
instead of Date. Any code expecting to receive a Date object must be
updated.
Note: As stated in the official docs, timestampsInSnapshots is going to be removed in a future release so make sure to remove it altogether.
For older versions of firebase-admin (6.5.1 and below)
This should do the work:
const admin = require('firebase-admin');
admin.initializeApp();
const firestore = admin.firestore();
// Add this magical line of code:
firestore.settings({ timestampsInSnapshots: true });
Then in your function use the firestore object directly:
firestore.doc(`/mycollection/${id}`).set({ it: 'works' })

I can't setup a react apollo mongodb app => resolvers with mongo / mongoose / NO METEOR

I'm currently learning Apollo, I'm a front end developer ( angular 1.5 over half a year for the background )
I have a very little experience with mongodb, and also with apollo ( trhough a meteor app )
I've read several times the Apollo doc, parsed Google with the keywords apollo, react, mongodb, resolvers, with various combinations ... ( no results )
I need to build a little React app (POC) which handle query, mutations, and subscriptions which would persist data with mongodb ( or another DB, I indicate this one since this is only one I've worked with so far ).
I cannot use Meteor.
My problem is that I can't find proper examples for graphql resolver working with mongo for all cases I need ( query, sub, mutate).
Would you have some boilerplate to provide , to help me to understand the mecanism ?
Thanks.
If you do not want to go through some tutorials. You could look at the githunt project. It is a apollo-graphql implementation with queries, mutations and subscriptions. It does not use a mongoDB, but this should be an easy change.
server: https://github.com/apollographql/GitHunt-API/tree/master/api
client: https://github.com/apollographql/GitHunt-React
Cheers
I think graphqly is the answer for you.
import graphly from "graphqly";
const gBuilder = graphly.createBuilder();
// define types, inputs ... (in any order)
gBuilder.type("Products").implements("List").def(`
products: [Product]!
`);
gBuilder.type("Product").def(`
id: ID!
name: String!
link: String
price: Int
`);
// we're too lazy to define a separate input, so we can `extend` other structure
gBuilder.input("ProductInput").ext("Product");
gBuilder.enum("ProductOrder").def(`
PRICE_DESCENDING
PRICE_ASCENDING
NEWEST
`);
// define interface `List`
gBuilder.iface("List").def(`
total: Int!,
offset: Int!,
limit: Int!,
# number of items actually in this window
size: Int!
`);
gBuilder.query(`
products(limit: Int = 20, offset: Int = 0, filter: ProductFilter): Products
`)
.resolve((root, args, context) => {
// your resolver here
// `this` is binded to the current Query instance
});
So, this is a good start for server only part with mongo / mongoose :
https://github.com/khadorkin/apollo-server-mongoose
I've enhanced this, I'll provide a link to the github repo in a few days.
Here is the repo.
Still work to be done, specially about subscriptions, but it might be a good start
Link to Github repo