-
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
Draft
fredzqm
wants to merge
46
commits into
master
Choose a base branch
from
fz/gen-schema-init
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 27 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
d2f9774
Generate schema in fdc init
fredzqm f8cdc0f
tested
fredzqm ae7e61e
Merge remote-tracking branch 'origin/master' into fz/gen-schema-init
fredzqm 9239426
Merge branch 'master' into fz/gen-schema-init
fredzqm 6208153
Merge branch 'master' into fz/gen-schema-init
fredzqm 091706d
Merge branch 'master' into fz/gen-schema-init
fredzqm 909ef53
Merge remote-tracking branch 'origin/master' into fz/gen-schema-init
fredzqm c3c08c9
tos
fredzqm e9eec2a
tweaks
fredzqm 68ea00f
m
fredzqm ac584ce
m
fredzqm 7290205
vaib code a test
fredzqm 1f84dc3
CHANGELOG
fredzqm bc2647e
m
fredzqm 1beed8d
Merge branch 'master' into fz/gen-schema-init
fredzqm 74d8710
Merge branch 'master' into fz/gen-schema-init
fredzqm ae6868d
m
fredzqm a59900f
Merge remote-tracking branch 'origin/master' into fz/gen-schema-init
fredzqm adfa8b8
Update src/init/features/dataconnect/index.ts
fredzqm 1923130
Update src/init/features/dataconnect/index.ts
fredzqm d41bd43
format
fredzqm 220a79d
m
fredzqm 9bead7f
clean
fredzqm ee4c8c0
Merge branch 'master' into fz/gen-schema-init
fredzqm 345d54a
Update ensureApis.ts
fredzqm 5a82f27
Merge branch 'master' into fz/gen-schema-init
fredzqm eefd4ce
Merge branch 'master' into fz/gen-schema-init
fredzqm 8f452f5
Merge branch 'master' into fz/gen-schema-init
fredzqm 46967ed
Show GiF ToS in firebase login
fredzqm d5e0621
Merge branch 'master' into fz/show-gif-tos
fredzqm 2fa36c0
tweaks
fredzqm d1d1100
Merge remote-tracking branch 'origin/master' into fz/show-gif-tos
fredzqm b0f3bc5
Merge remote-tracking branch 'origin/master' into fz/show-gif-tos
fredzqm 1ef575f
Merge branch 'master' into fz/show-gif-tos
fredzqm 3db2767
Merge remote-tracking branch 'origin/master' into fz/show-gif-tos
fredzqm dd092dd
tweaks
fredzqm a1f20db
Merge remote-tracking branch 'origin/fz/show-gif-tos' into fz/show-gi…
fredzqm 6b7a8da
Merge branch 'master' into fz/show-gif-tos
fredzqm b19986d
Merge remote-tracking branch 'origin/master' into fz/show-gif-tos
fredzqm 129c382
Merge branch 'master' into fz/show-gif-tos
fredzqm f884056
Merge remote-tracking branch 'origin/fz/show-gif-tos' into fz/show-gi…
fredzqm 55d87d0
Merge branch 'fz/show-gif-tos' into fz/gen-schema-init
fredzqm 2e09e7e
merge
fredzqm cd14029
m
fredzqm 04b1c42
merge
fredzqm 2403de2
adjust question
fredzqm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
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); | ||
} | ||
|
||
export async function ensureGIFApis(projectId: string): Promise<void> { | ||
await ensure(projectId, api.cloudAiCompanionOrigin(), prefix); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { expect } from "chai"; | ||
import { extractCodeBlock } from "./fdcExperience"; | ||
|
||
describe("extractCodeBlock", () => { | ||
it("should extract a basic GraphQL query block", () => { | ||
const text = | ||
'Here is a GraphQL query:\n```graphql\nquery GetUser { user(id: "1") { name email } }\n```\nThanks!'; | ||
const expected = 'query GetUser { user(id: "1") { name email } }'; | ||
expect(extractCodeBlock(text)).to.eq(expected); | ||
}); | ||
|
||
it("should extract a multi-line GraphQL mutation block", () => { | ||
const text = ` | ||
Some preamble. | ||
\`\`\`graphql | ||
mutation CreatePost($title: String!, $content: String!) { | ||
createPost(title: $title, content: $content) { | ||
id | ||
title | ||
} | ||
} | ||
\`\`\` | ||
Followed by some description. | ||
`; | ||
const expected = `mutation CreatePost($title: String!, $content: String!) { | ||
createPost(title: $title, content: $content) { | ||
id | ||
title | ||
} | ||
}`; | ||
expect(extractCodeBlock(text)).to.eq(expected); | ||
}); | ||
|
||
it("should extract a GraphQL fragment block", () => { | ||
const text = "```graphql\nfragment UserFields on User { id name }\n```"; | ||
const expected = "fragment UserFields on User { id name }"; | ||
expect(extractCodeBlock(text)).to.eq(expected); | ||
}); | ||
|
||
it("should extract an empty GraphQL code block", () => { | ||
const text = "```graphql\n\n```"; | ||
const expected = ""; | ||
expect(extractCodeBlock(text)).to.eq(expected); | ||
}); | ||
|
||
it("should extract a GraphQL schema definition block", () => { | ||
const text = ` | ||
\`\`\`graphql | ||
type Query { | ||
hello: String | ||
} | ||
|
||
schema { | ||
query: Query | ||
} | ||
\`\`\` | ||
`; | ||
const expected = `type Query { | ||
hello: String | ||
} | ||
|
||
schema { | ||
query: Query | ||
}`; | ||
expect(extractCodeBlock(text)).to.eq(expected); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import { Setup } from "../.."; | |
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 { Schema, Service, File, Platform } from "../../../dataconnect/types"; | |
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"); | ||
|
@@ -110,8 +111,7 @@ export async function askQuestions(setup: Setup): Promise<void> { | |
default: true, | ||
})); | ||
if (shouldConfigureBackend) { | ||
// TODO: Prompt for app idea and use GiF backend to generate them. | ||
info = await promptForService(info); | ||
info = await promptForSchema(setup, info); | ||
info = await promptForCloudSQL(setup, info); | ||
|
||
info.shouldProvisionCSQL = !!( | ||
|
@@ -425,12 +425,34 @@ async function promptForCloudSQL(setup: Setup, info: RequiredInfo): Promise<Requ | |
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()), | ||
}); | ||
if ( | ||
fredzqm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setup.projectId && | ||
(await confirm({ | ||
message: `Do you want Gemini to help generate a schema for your service?`, | ||
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. "Do you want Gemini in Firebase to help generate a schema for your service" 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. Done~ |
||
default: false, | ||
})) | ||
) { | ||
logBullet( | ||
`Check out the terms of service of Gemini in Firebase https://firebase.google.com/docs/gemini-in-firebase/set-up-gemini#required-permissions`, | ||
); | ||
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; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.