-
Notifications
You must be signed in to change notification settings - Fork 1k
[FDC] Generate schema during init dataconnect flow #8596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 10 commits
d2f9774
f8cdc0f
ae7e61e
9239426
6208153
091706d
909ef53
c3c08c9
e9eec2a
68ea00f
ac584ce
7290205
1f84dc3
bc2647e
1beed8d
74d8710
ae6868d
a59900f
adfa8b8
1923130
d41bd43
220a79d
9bead7f
ee4c8c0
345d54a
5a82f27
eefd4ce
8f452f5
46967ed
d5e0621
2fa36c0
d1d1100
b0f3bc5
1ef575f
3db2767
dd092dd
a1f20db
6b7a8da
b19986d
129c382
f884056
55d87d0
2e09e7e
cd14029
04b1c42
2403de2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
import * as api from "../api"; | ||
import { ensure } from "../ensureApiEnabled"; | ||
|
||
const prefix = "dataconnect"; | ||
|
||
export async function ensureApis(projectId: string): Promise<void> { | ||
const prefix = "dataconnect"; | ||
await ensure(projectId, api.dataconnectOrigin(), prefix); | ||
await ensure(projectId, api.cloudSQLAdminOrigin(), prefix); | ||
await ensure(projectId, api.computeOrigin(), prefix); | ||
} | ||
|
||
export async function ensureSparkApis(projectId: string): Promise<void> { | ||
const prefix = "dataconnect"; | ||
// These are the APIs that can be enabled without a billing account. | ||
await ensure(projectId, api.cloudSQLAdminOrigin(), prefix); | ||
await ensure(projectId, api.cloudAiCompanionOrigin(), prefix); | ||
} | ||
|
||
export async function ensureGIFApis(projectId: string): Promise<void> { | ||
await ensure(projectId, api.cloudAiCompanionOrigin(), prefix); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
import { provisionCloudSql } from "../../../dataconnect/provisionCloudSql"; | ||
import { checkFreeTrialInstanceUsed, upgradeInstructions } from "../../../dataconnect/freeTrial"; | ||
import * as cloudsql from "../../../gcp/cloudsql/cloudsqladmin"; | ||
import { ensureApis, ensureSparkApis } from "../../../dataconnect/ensureApis"; | ||
import { ensureApis, ensureGIFApis, ensureSparkApis } from "../../../dataconnect/ensureApis"; | ||
import { | ||
listLocations, | ||
listAllServices, | ||
|
@@ -19,10 +19,11 @@ | |
import { parseCloudSQLInstanceName, parseServiceName } from "../../../dataconnect/names"; | ||
import { logger } from "../../../logger"; | ||
import { readTemplateSync } from "../../../templates"; | ||
import { logBullet, envOverride } from "../../../utils"; | ||
import { logBullet, envOverride, promiseWithSpinner } from "../../../utils"; | ||
import { isBillingEnabled } from "../../../gcp/cloudbilling"; | ||
import * as sdk from "./sdk"; | ||
import { getPlatformFromFolder } from "../../../dataconnect/fileUtils"; | ||
import { extractCodeBlock, generateSchema } from "../../../gif/fdcExperience"; | ||
|
||
const DATACONNECT_YAML_TEMPLATE = readTemplateSync("init/dataconnect/dataconnect.yaml"); | ||
const CONNECTOR_YAML_TEMPLATE = readTemplateSync("init/dataconnect/connector.yaml"); | ||
|
@@ -33,7 +34,7 @@ | |
// serviceEnvVar is used by Firebase Console to specify which service to import. | ||
// It should be in the form <location>/<serviceId> | ||
// It must be an existing service - if set to anything else, we'll ignore it. | ||
const serviceEnvVar = () => envOverride("FDC_SERVICE", ""); | ||
|
||
export interface RequiredInfo { | ||
serviceId: string; | ||
|
@@ -76,7 +77,7 @@ | |
|
||
// askQuestions prompts the user about the Data Connect service they want to init. Any prompting | ||
// logic should live here, and _no_ actuation logic should live here. | ||
export async function askQuestions(setup: Setup): Promise<void> { | ||
const hasBilling = await isBillingEnabled(setup); | ||
if (setup.projectId) { | ||
hasBilling ? await ensureApis(setup.projectId) : await ensureSparkApis(setup.projectId); | ||
|
@@ -111,7 +112,7 @@ | |
})); | ||
if (shouldConfigureBackend) { | ||
// TODO: Prompt for app idea and use GiF backend to generate them. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove TODO? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, removed |
||
info = await promptForService(info); | ||
info = await promptForSchema(setup, info); | ||
info = await promptForCloudSQL(setup, info); | ||
|
||
info.shouldProvisionCSQL = !!( | ||
|
@@ -130,10 +131,10 @@ | |
|
||
// actuate writes product specific files and makes product specifc API calls. | ||
// It does not handle writing firebase.json and .firebaserc | ||
export async function actuate(setup: Setup, config: Config, options: any): Promise<void> { | ||
Check warning on line 134 in src/init/features/dataconnect/index.ts
|
||
// Most users will want to persist data between emulator runs, so set this to a reasonable default. | ||
const dir: string = config.get("dataconnect.source", "dataconnect"); | ||
const dataDir = config.get("emulators.dataconnect.dataDir", `${dir}/.dataconnect/pgliteData`); | ||
config.set("emulators.dataconnect.dataDir", dataDir); | ||
|
||
const info = setup.featureInfo?.dataconnect; | ||
|
@@ -425,12 +426,33 @@ | |
return info; | ||
} | ||
|
||
async function promptForService(info: RequiredInfo): Promise<RequiredInfo> { | ||
async function promptForSchema(setup: Setup, info: RequiredInfo): Promise<RequiredInfo> { | ||
if (info.serviceId === "") { | ||
info.serviceId = await input({ | ||
message: "What ID would you like to use for this service?", | ||
default: basename(process.cwd()), | ||
}); | ||
logBullet( | ||
fredzqm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`Check out the terms of service of Gemini in Firebase https://firebase.google.com/docs/gemini-in-firebase/set-up-gemini#required-permissions`, | ||
); | ||
if ( | ||
fredzqm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await confirm({ | ||
message: `Do you want Gemini to help generate the schema?`, | ||
fredzqm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default: true, | ||
fredzqm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
) { | ||
await ensureGIFApis(setup.projectId!); | ||
const prompt = await input({ | ||
message: "Describe the app you are building:", | ||
default: "movie rating app", | ||
}); | ||
const schema = await promiseWithSpinner( | ||
() => generateSchema(prompt, setup.projectId!), | ||
"Generating the Data Connect Schema...", | ||
); | ||
info.schemaGql = [{ path: "schema.gql", content: extractCodeBlock(schema) }]; | ||
info.connectors = [emptyConnector]; | ||
} | ||
} | ||
return info; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.