Skip to content

Commit 09e5df7

Browse files
fredzqmjoehan
andauthored
[FDC] Update init template (#9033)
* update FDC templates * template * m * Update dataconnect.yaml to clarify schemaValidation --------- Co-authored-by: Joe Hanley <[email protected]>
1 parent ea00598 commit 09e5df7

File tree

6 files changed

+165
-173
lines changed

6 files changed

+165
-173
lines changed

src/init/features/dataconnect/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export async function askQuestions(setup: Setup): Promise<void> {
115115
);
116116
}
117117
info.appDescription = await input({
118-
message: `Describe your app to automatically generate a schema [Enter to skip]:`,
118+
message: `Describe your app to automatically generate a schema with Gemini [Enter to skip]:`,
119119
});
120120
if (info.appDescription) {
121121
configstore.set("gemini", true);
@@ -366,13 +366,20 @@ export async function postSetup(setup: Setup, config: Config, options: Options):
366366
);
367367
}
368368

369-
if (setup.projectId && !setup.isBillingEnabled) {
370-
instructions.push(upgradeInstructions(setup.projectId));
369+
if (setup.projectId) {
370+
if (!setup.isBillingEnabled) {
371+
instructions.push(upgradeInstructions(setup.projectId));
372+
}
371373
}
374+
instructions.push(
375+
`Install the Data Connect VS Code Extensions. You can explore Data Connect Query on local pgLite or Cloud SQL Postgres Instance.`,
376+
);
372377

373-
logger.info(`\n${clc.bold("To get started with Firebase Data Connect:")}`);
374-
for (const i of instructions) {
375-
logBullet(i + "\n");
378+
if (instructions.length) {
379+
logger.info(`\n${clc.bold("To get started with Firebase Data Connect:")}`);
380+
for (const i of instructions) {
381+
logBullet(i + "\n");
382+
}
376383
}
377384
}
378385

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
11
connectorId: __connectorId__
2-
## ## Here's an example of how to add generated SDKs.
3-
## ## You'll need to replace the outputDirs with ones pointing to where you want the generated code in your app.
4-
# generate:
5-
# javascriptSdk:
6-
# outputDir: <Path where you want the generated SDK to be written to, relative to this file>
7-
# package: "@firebasegen/my-connector"
8-
# packageJsonDir: < Optional. Path to your Javascript app's package.json>
9-
# swiftSdk:
10-
# outputDir: <Path where you want the generated SDK to be written to, relative to this file>
11-
# package: DefaultConnector
12-
# kotlinSdk:
13-
# outputDir: <Path where you want the generated SDK to be written to, relative to this file>
14-
# package: connectors.default
15-
# dartSdk:
16-
# outputDir: <Path where you want the generated SDK to be written to, relative to this file>
17-
# package: default_connector

templates/init/dataconnect/dataconnect.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ schema:
88
database: __cloudSqlDatabase__
99
cloudSql:
1010
instanceId: __cloudSqlInstanceId__
11-
# schemaValidation: "COMPATIBLE"
11+
# schemaValidation: "STRICT" # STRICT mode makes Postgres schema match Data Connect exactly.
12+
# schemaValidation: "COMPATIBLE" # COMPATIBLE mode makes Postgres schema compatible with Data Connect.
1213
connectorDirs: __connectorDirs__
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
# # Example mutations for a simple movie app
1+
# Example mutations for a simple movie app
22

3-
# # Create a movie based on user input
4-
# mutation CreateMovie($title: String!, $genre: String!, $imageUrl: String!)
5-
# @auth(level: USER_EMAIL_VERIFIED, insecureReason: "Any email verified users can create a new movie.") {
6-
# movie_insert(data: { title: $title, genre: $genre, imageUrl: $imageUrl })
7-
# }
3+
# Create a movie based on user input
4+
mutation CreateMovie($title: String!, $genre: String!, $imageUrl: String!)
5+
@auth(level: USER_EMAIL_VERIFIED, insecureReason: "Any email verified users can create a new movie.") {
6+
movie_insert(data: { title: $title, genre: $genre, imageUrl: $imageUrl })
7+
}
88

9-
# # Upsert (update or insert) a user's username based on their auth.uid
10-
# mutation UpsertUser($username: String!) @auth(level: USER) {
11-
# # The "auth.uid" server value ensures that users can only register their own user.
12-
# user_upsert(data: { id_expr: "auth.uid", username: $username })
13-
# }
9+
# Upsert (update or insert) a user's username based on their auth.uid
10+
mutation UpsertUser($username: String!) @auth(level: USER) {
11+
# The "auth.uid" server value ensures that users can only register their own user.
12+
user_upsert(data: { id_expr: "auth.uid", username: $username })
13+
}
1414

15-
# # Add a review for a movie
16-
# mutation AddReview($movieId: UUID!, $rating: Int!, $reviewText: String!)
17-
# @auth(level: USER) {
18-
# review_upsert(
19-
# data: {
20-
# userId_expr: "auth.uid"
21-
# movieId: $movieId
22-
# rating: $rating
23-
# reviewText: $reviewText
24-
# # reviewDate defaults to today in the schema. No need to set it manually.
25-
# }
26-
# )
27-
# }
15+
# Add a review for a movie
16+
mutation AddReview($movieId: UUID!, $rating: Int!, $reviewText: String!)
17+
@auth(level: USER) {
18+
review_upsert(
19+
data: {
20+
userId_expr: "auth.uid"
21+
movieId: $movieId
22+
rating: $rating
23+
reviewText: $reviewText
24+
# reviewDate defaults to today in the schema. No need to set it manually.
25+
}
26+
)
27+
}
2828

29-
# # Logged in user can delete their review for a movie
30-
# mutation DeleteReview($movieId: UUID!) @auth(level: USER) {
31-
# # The "auth.uid" server value ensures that users can only delete their own reviews.
32-
# review_delete(key: { userId_expr: "auth.uid", movieId: $movieId })
33-
# }
29+
# Logged in user can delete their review for a movie
30+
mutation DeleteReview($movieId: UUID!) @auth(level: USER) {
31+
# The "auth.uid" server value ensures that users can only delete their own reviews.
32+
review_delete(key: { userId_expr: "auth.uid", movieId: $movieId })
33+
}
Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
1-
# # Example queries for a simple movie app.
1+
# Example queries for a simple movie app.
22

3-
# # @auth() directives control who can call each operation.
4-
# # Anyone should be able to list all movies, so the auth level is set to PUBLIC
5-
# query ListMovies @auth(level: PUBLIC, insecureReason: "Anyone can list all movies.") {
6-
# movies {
7-
# id
8-
# title
9-
# imageUrl
10-
# genre
11-
# }
12-
# }
3+
# @auth() directives control who can call each operation.
4+
# Anyone should be able to list all movies, so the auth level is set to PUBLIC
5+
query ListMovies @auth(level: PUBLIC, insecureReason: "Anyone can list all movies.") {
6+
movies {
7+
id
8+
title
9+
imageUrl
10+
genre
11+
}
12+
}
1313

14-
# # List all users, only admins should be able to list all users, so we use NO_ACCESS
15-
# query ListUsers @auth(level: NO_ACCESS) {
16-
# users {
17-
# id
18-
# username
19-
# }
20-
# }
14+
# List all users, only admins should be able to list all users, so we use NO_ACCESS
15+
query ListUsers @auth(level: NO_ACCESS) {
16+
users {
17+
id
18+
username
19+
}
20+
}
2121

22-
# # Logged in users can list all their reviews and movie titles associated with the review
23-
# # Since the query uses the uid of the current authenticated user, we set auth level to USER
24-
# query ListUserReviews @auth(level: USER) {
25-
# user(key: { id_expr: "auth.uid" }) {
26-
# id
27-
# username
28-
# # <field>_on_<foreign_key_field> makes it easy to grab info from another table
29-
# # Here, we use it to grab all the reviews written by the user.
30-
# reviews: reviews_on_user {
31-
# rating
32-
# reviewDate
33-
# reviewText
34-
# movie {
35-
# id
36-
# title
37-
# }
38-
# }
39-
# }
40-
# }
22+
# Logged in users can list all their reviews and movie titles associated with the review
23+
# Since the query uses the uid of the current authenticated user, we set auth level to USER
24+
query ListUserReviews @auth(level: USER) {
25+
user(key: { id_expr: "auth.uid" }) {
26+
id
27+
username
28+
# <field>_on_<foreign_key_field> makes it easy to grab info from another table
29+
# Here, we use it to grab all the reviews written by the user.
30+
reviews: reviews_on_user {
31+
rating
32+
reviewDate
33+
reviewText
34+
movie {
35+
id
36+
title
37+
}
38+
}
39+
}
40+
}
4141

42-
# # Get movie by id
43-
# query GetMovieById($id: UUID!) @auth(level: PUBLIC, insecureReason: "Anyone can get a movie by id.") {
44-
# movie(id: $id) {
45-
# id
46-
# title
47-
# imageUrl
48-
# genre
49-
# metadata: movieMetadata_on_movie {
50-
# rating
51-
# releaseYear
52-
# description
53-
# }
54-
# reviews: reviews_on_movie {
55-
# reviewText
56-
# reviewDate
57-
# rating
58-
# user {
59-
# id
60-
# username
61-
# }
62-
# }
63-
# }
64-
# }
42+
# Get movie by id
43+
query GetMovieById($id: UUID!) @auth(level: PUBLIC, insecureReason: "Anyone can get a movie by id.") {
44+
movie(id: $id) {
45+
id
46+
title
47+
imageUrl
48+
genre
49+
metadata: movieMetadata_on_movie {
50+
rating
51+
releaseYear
52+
description
53+
}
54+
reviews: reviews_on_movie {
55+
reviewText
56+
reviewDate
57+
rating
58+
user {
59+
id
60+
username
61+
}
62+
}
63+
}
64+
}
6565

66-
# # Search for movies, actors, and reviews
67-
# query SearchMovie($titleInput: String, $genre: String) @auth(level: PUBLIC, insecureReason: "Anyone can search for movies.") {
68-
# movies(
69-
# where: {
70-
# _and: [{ genre: { eq: $genre } }, { title: { contains: $titleInput } }]
71-
# }
72-
# ) {
73-
# id
74-
# title
75-
# genre
76-
# imageUrl
77-
# }
78-
# }
66+
# Search for movies, actors, and reviews
67+
query SearchMovie($titleInput: String, $genre: String) @auth(level: PUBLIC, insecureReason: "Anyone can search for movies.") {
68+
movies(
69+
where: {
70+
_and: [{ genre: { eq: $genre } }, { title: { contains: $titleInput } }]
71+
}
72+
) {
73+
id
74+
title
75+
genre
76+
imageUrl
77+
}
78+
}

templates/init/dataconnect/schema.gql

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
# # Example schema for simple movie review app
1+
# Example schema for simple movie review app
22

3-
# # User table is keyed by Firebase Auth UID.
4-
# type User @table {
5-
# # `@default(expr: "auth.uid")` sets it to Firebase Auth UID during insert and upsert.
6-
# id: String! @default(expr: "auth.uid")
7-
# username: String! @col(dataType: "varchar(50)")
8-
# # The `user: User!` field in the Review table generates the following one-to-many query field.
9-
# # reviews_on_user: [Review!]!
10-
# # The `Review` join table the following many-to-many query field.
11-
# # movies_via_Review: [Movie!]!
12-
# }
3+
# User table is keyed by Firebase Auth UID.
4+
type User @table {
5+
# `@default(expr: "auth.uid")` sets it to Firebase Auth UID during insert and upsert.
6+
id: String! @default(expr: "auth.uid")
7+
username: String! @col(dataType: "varchar(50)")
8+
# The `user: User!` field in the Review table generates the following one-to-many query field.
9+
# reviews_on_user: [Review!]!
10+
# The `Review` join table the following many-to-many query field.
11+
# movies_via_Review: [Movie!]!
12+
}
1313

14-
# # Movie is keyed by a randomly generated UUID.
15-
# type Movie @table {
16-
# # If you do not pass a 'key' to `@table`, Data Connect automatically adds the following 'id' column.
17-
# # Feel free to uncomment and customize it.
18-
# # id: UUID! @default(expr: "uuidV4()")
19-
# title: String!
20-
# imageUrl: String!
21-
# genre: String
22-
# }
14+
# Movie is keyed by a randomly generated UUID.
15+
type Movie @table {
16+
# If you do not pass a 'key' to `@table`, Data Connect automatically adds the following 'id' column.
17+
# Feel free to uncomment and customize it.
18+
# id: UUID! @default(expr: "uuidV4()")
19+
title: String!
20+
imageUrl: String!
21+
genre: String
22+
}
2323

24-
# # MovieMetadata is a metadata attached to a Movie.
25-
# # Movie <-> MovieMetadata is a one-to-one relationship
26-
# type MovieMetadata @table {
27-
# # @unique ensures each Movie can only one MovieMetadata.
28-
# movie: Movie! @unique
29-
# # The movie field adds the following foreign key field. Feel free to uncomment and customize it.
30-
# # movieId: UUID!
31-
# rating: Float
32-
# releaseYear: Int
33-
# description: String
34-
# }
24+
# MovieMetadata is a metadata attached to a Movie.
25+
# Movie <-> MovieMetadata is a one-to-one relationship
26+
type MovieMetadata @table {
27+
# @unique ensures each Movie can only one MovieMetadata.
28+
movie: Movie! @unique
29+
# The movie field adds the following foreign key field. Feel free to uncomment and customize it.
30+
# movieId: UUID!
31+
rating: Float
32+
releaseYear: Int
33+
description: String
34+
}
3535

36-
# # Reviews is a join table between User and Movie.
37-
# # It has a composite primary keys `userUid` and `movieId`.
38-
# # A user can leave reviews for many movies. A movie can have reviews from many users.
39-
# # User <-> Review is a one-to-many relationship
40-
# # Movie <-> Review is a one-to-many relationship
41-
# # Movie <-> User is a many-to-many relationship
42-
# type Review @table(name: "Reviews", key: ["movie", "user"]) {
43-
# user: User!
44-
# # The user field adds the following foreign key field. Feel free to uncomment and customize it.
45-
# # userUid: String!
46-
# movie: Movie!
47-
# # The movie field adds the following foreign key field. Feel free to uncomment and customize it.
48-
# # movieId: UUID!
49-
# rating: Int
50-
# reviewText: String
51-
# reviewDate: Date! @default(expr: "request.time")
52-
# }
36+
# Reviews is a join table between User and Movie.
37+
# It has a composite primary keys `userUid` and `movieId`.
38+
# A user can leave reviews for many movies. A movie can have reviews from many users.
39+
# User <-> Review is a one-to-many relationship
40+
# Movie <-> Review is a one-to-many relationship
41+
# Movie <-> User is a many-to-many relationship
42+
type Review @table(name: "Reviews", key: ["movie", "user"]) {
43+
user: User!
44+
# The user field adds the following foreign key field. Feel free to uncomment and customize it.
45+
# userUid: String!
46+
movie: Movie!
47+
# The movie field adds the following foreign key field. Feel free to uncomment and customize it.
48+
# movieId: UUID!
49+
rating: Int
50+
reviewText: String
51+
reviewDate: Date! @default(expr: "request.time")
52+
}

0 commit comments

Comments
 (0)