GoogleCloudPlatform / functions-framework-nodejs

FaaS (Function as a service) framework for writing portable Node.js functions
Apache License 2.0
1.28k stars 158 forks source link

Documentation on how to use with Firebase Firestore emulators #583

Open jackatomix opened 6 months ago

jackatomix commented 6 months ago

We have an app that uses a Firestore database, and locally we can use the Firestore Firebase emulators provided by firebase-tools to avoid connecting to a remote/shared database.

It's clear enough on how to connect to the emulators locally for reading/writing data with @google-cloud/firestore, and it's also clear how I can deploy a function built with the Functions Framework that is triggered by a Firestore event. What I'm not clear on is how we can trigger a function built with the Functions Framework when data is written to said Firestore emulator.

Is this something that can be achieved with the Functions Framework, and if so, how does it need to be set up?

HKWinterhalter commented 6 months ago

Hi @jackatomix, it sounds like this is a question for the firebase-tools owners. I was able to find some guides that may be related: https://firebase.google.com/docs/functions/local-emulator and https://firebase.google.com/docs/functions/local-shell.

jackatomix commented 6 months ago

Hi @jackatomix, it sounds like this is a question for the firebase-tools owners. I was able to find some guides that may be related: https://firebase.google.com/docs/functions/local-emulator and https://firebase.google.com/docs/functions/local-shell.

Thanks @HKWinterhalter, I agree this is a bit of a grey area. I asked the question here as there is documentation in this repo on how to trigger functions from the Pub/Sub emulator, and I figure this is a similar use case. In fact, I think I'm asking about pretty much the same solution as was in #101 .

The documentation you've provided doesn't seem related to the Firestore emulator, more for the more general Firebase Functions abstraction. We do actually use those tools for other areas of the app, and local development is just fine with it. But for reasons that aren't important to this ticket, we'd like to avoid using it going forward.

The best I can tell what I'd like isn't explicitly a supported option between firebase-tools and the Functions Framework. I think the correct solution is for firebase-tools to allow sending a CloudEvent out via the Eventarc emulator to the function running from the Functions Framework, but that would add some additional complications.