Fix Data Connect skill: upsert key, fetch policy, and emulator workflow#144
Fix Data Connect skill: upsert key, fetch policy, and emulator workflow#144crrapi wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Firebase Data Connect documentation to clarify schema design for upserts (using composite primary keys instead of surrogate IDs), local seeding via the SDK, offline emulator usage, and fetch policy options for the Web SDK. The review feedback correctly points out that generated action shortcuts do not accept fetch policy options directly and suggests updating configuration examples to use the correct relative path depth (../../) to match the new documentation.
| await executeQuery(queryRef, { fetchPolicy: QueryFetchPolicy.CACHE_ONLY }); | ||
| await executeQuery(queryRef, { fetchPolicy: QueryFetchPolicy.SERVER_ONLY }); | ||
| await listMovies(dataConnect, { fetchPolicy: QueryFetchPolicy.SERVER_ONLY }); |
There was a problem hiding this comment.
The generated action shortcuts (such as listMovies) do not accept an options object (like { fetchPolicy }) as an argument. They only accept a DataConnect instance and/or variables. To customize the fetch policy or other execution options, you must use executeQuery with the query reference.
We should remove the incorrect listMovies example to prevent compilation errors for users following this guide.
| await executeQuery(queryRef, { fetchPolicy: QueryFetchPolicy.CACHE_ONLY }); | |
| await executeQuery(queryRef, { fetchPolicy: QueryFetchPolicy.SERVER_ONLY }); | |
| await listMovies(dataConnect, { fetchPolicy: QueryFetchPolicy.SERVER_ONLY }); | |
| await executeQuery(queryRef, { fetchPolicy: QueryFetchPolicy.CACHE_ONLY }); | |
| await executeQuery(queryRef, { fetchPolicy: QueryFetchPolicy.SERVER_ONLY }); |
There was a problem hiding this comment.
Kept intentionally. The generated query shortcuts do accept ExecuteQueryOptions as the trailing argument — the SDK emits overloads listMovies(dc, options?) and recentReviews(dc, vars?, options?), and passing { fetchPolicy: SERVER_ONLY } to them is verified working on firebase 12.x (it's exactly what turns a stale cached read into a fresh one). Only mutation shortcuts (e.g. addReview) omit the options argument.
| @@ -87,6 +87,10 @@ generate: | |||
| outputDir: "../ios/MyApp/DataConnect" | |||
There was a problem hiding this comment.
Since outputDir is resolved relative to the connector.yaml directory (typically dataconnect/connector/), targeting sibling directories at the project root requires walking up two levels (../../). To align with the helpful note added below, we should update the examples in this configuration block (including javascriptSdk and kotlinSdk above) to use ../../ instead of ../ to avoid confusing readers.
| outputDir: "../ios/MyApp/DataConnect" | |
| outputDir: "../../ios/MyApp/DataConnect" |
There was a problem hiding this comment.
Applied in 55a8cf2 — updated the javascriptSdk/kotlinSdk/swiftSdk examples in this block to ../../ so they match the note.
…lator behavior - examples: Review must use a composite (movie, user) primary key so review_upsert has a conflict target; the surrogate-id + @unique version fails to compile. Update the dependent MyReviews/DeleteReview operations. - operations: note that _upsert matches on the primary key, not @unique. - sdk_web: queries default to PREFER_CACHE; pass an options object with SERVER_ONLY for fresh/polled reads, and fix the fetch-policy call shape. - config: offline validation/SDK generation runs through the emulator with a demo project; flag that emulator UUIDs are returned without hyphens; clarify outputDir is relative to connector.yaml. - data_seeding: show how to execute seeds against the emulator via the SDK.
f7ec7e6 to
55a8cf2
Compare
What
An accuracy pass on the
firebase-data-connect-basicsskill. Each change fixes something an agent following the current docs hits in practice.Changes
examples.md— the Movie Review schema doesn't compile.Reviewuses a surrogateidPK with@unique(["movie","user"]), butreview_upsertkeys on the primary key, so it fails withkey id is required in upsert but is not set in data. Switched to a composite@table(key: ["movie","user"])PK (which is also the one-review-per-user guarantee) and updated the dependentMyReviews/DeleteReviewoperations.operations.md— note that_upsertmatches on the primary key, not on@uniqueconstraints.sdk_web.md— document that queries default toPREFER_CACHEand that fresh/polled/live reads needSERVER_ONLY; correct the fetch-policy call shape to the{ fetchPolicy }options object.config.md— offline validation / SDK generation runs through the emulator with ademo-project (compileandsdk:generateneed credentials); flag that the emulator returns UUIDs without hyphens; clarifyoutputDiris relative toconnector.yaml.data_seeding.md— show how to actually execute seeds against the emulator via the generated SDK (the docs never showed a runner).Notes
Verified against
firebase-tools15.22.3 /dataconnect-emulator3.4.14 by building a working movie-review app.scripts/format.sh --checkpasses; docs-only, no skill behavior contract changed.