Repository navigation
Closed
Labels
emulator: dataconnectIssues related to the dataconnect emulatoremulators: functionsreproducibletype: bug
Description
[REQUIRED] Environment info
firebase-tools: 14.0.0
Platform: macOS
[REQUIRED] Test case
index.ts
import { initializeApp } from "firebase-admin";
import { getDataConnect } from "firebase-admin/data-connect";
import { onRequest } from "firebase-functions/https";
initializeApp();
export const callFn = onRequest(async (_req, res) => {
const dataConnect = getDataConnect({
location: "us-central1",
serviceId: "dataconnect",
});
const result = await dataConnect.executeGraphql(
`mutation {
movie_insert(
data: {
id: "11111111222233334444555555555555"
genre: ""
imageUrl: ""
title: ""
}
)
}
`
);
res.status(200).json({ result });
});schema.gql
# Movie is keyed by a randomly generated UUID.
type Movie @table {
# If you do not pass a 'key' to `@table`, Data Connect automatically adds the following 'id' column.
# Feel free to uncomment and customize it.
# id: UUID! @default(expr: "uuidV4()")
title: String!
imageUrl: String!
genre: String
}[REQUIRED] Steps to reproduce
-
Create a firebase project with
Data Connect&Cloud Functionsin Typescript using:firebase init
-
Update the
functions/src/index.tsfile with the code above. -
Update the
dataconnect/schema/schema.gqlfile with the schema above. -
Run below command to install latest dependencies:
npm install firebase-admin@latest typescript@latest
-
Run emulator using the command below:
npm run build && firebase emulators:start -
Call the http function using the command below:
curl -X POST http://127.0.0.1:5001/<project-id>/us-central1/callFn
-
Check the error logs in the console.
[REQUIRED] Expected behavior
When running locally using emulators, the function should execute successfully and insert a new movie record into the Data Connect table.
[REQUIRED] Actual behavior
⚠ functions: Error: Resource "projects/<project-id>/locations/us-central1/services/dataconnect" was not found
at DataConnectApiClient.toFirebaseError (functions/node_modules/firebase-admin/lib/data-connect/data-connect-api-client-internal.js:161:16)
at functions/node_modules/firebase-admin/lib/data-connect/data-connect-api-client-internal.js:107:24
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async functions/lib/index.js:58:31
at async runFunction (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:506:9)
at async runHTTPS (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:531:5)
at async /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:694:21
⚠ Your function was killed because it raised an unhandled error.
i Request to function failed: Error: socket hang upMetadata
Metadata
Assignees
Labels
emulator: dataconnectIssues related to the dataconnect emulatoremulators: functionsreproducibletype: bug
Activity
[-]Unable to perform queries on **Data Connect** locally using **Cloud Functions** in emulator[/-][+]Unable to perform queries on `Data Connect` locally using `Cloud Functions` in emulator[/+]aalej commentedon Mar 28, 2025
Thanks for sharing a test case @OutdatedGuy! When trying to reproduce this issue, I noticed that the debug logs indicate that a request is being made to production instead of the Data Connect emulator, which could be causing the error. Did you notice any logs similar to below?
If you are trying to make a query on the Data Connect emulator, could you try updating your code to something like:
The Firebase CLI should be automatically setting Data Connect emulator host when it detects that the Data Connect emulator is being used.
If you are trying to connect to a production instance of Data Connect, could you double check if your
serviceIdmatches the one from yourdataconnect.yamlfile?OutdatedGuy commentedon Mar 28, 2025
Yes, I can see the accessing production service warning.
After updating the code I'm getting the different error below:Adding the above line worked in my main codebase (hurray 🎉), but I'm getting the below error in my demo (Minimum Reproducible Code).
Thanks @aalej for the help!
OutdatedGuy commentedon Mar 28, 2025
@aalej @joehan after updating
firebase-toolsto14.0.1I'm getting the below error:⚠ functions: Error: Error while making request: getaddrinfo ENOTFOUND http. Error code: ENOTFOUNDSo playing around a bit with host values I figured out that setting
process.env.DATA_CONNECT_EMULATOR_HOSTtohttp://127.0.0.1:9399instead of just127.0.0.1:9399causes the above issue.So it looks like this change from #8387 needs to be modified.