Skip to content

Commit f4a982f

Browse files
authored
improve FDC initial Schema template (#8160)
1 parent f32769b commit f4a982f

File tree

3 files changed

+46
-61
lines changed

3 files changed

+46
-61
lines changed
Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
11
# # Example mutations for a simple movie app
22

33
# # Create a movie based on user input
4-
# mutation CreateMovie(
5-
# $title: String!
6-
# $genre: String!
7-
# $imageUrl: String!
8-
# ) @auth(level: USER_EMAIL_VERIFIED) {
9-
# movie_insert(
10-
# data: {
11-
# title: $title
12-
# genre: $genre
13-
# imageUrl: $imageUrl
14-
# }
15-
# )
4+
# mutation CreateMovie($title: String!, $genre: String!, $imageUrl: String!)
5+
# @auth(level: USER_EMAIL_VERIFIED) {
6+
# movie_insert(data: { title: $title, genre: $genre, imageUrl: $imageUrl })
167
# }
178

189
# # Upsert (update or insert) a user's username based on their auth.uid
1910
# mutation UpsertUser($username: String!) @auth(level: USER) {
20-
# user_upsert(
21-
# data: {
22-
# id_expr: "auth.uid"
23-
# username: $username
24-
# }
25-
# )
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 })
2613
# }
2714

2815
# # Add a review for a movie
29-
# mutation AddReview(
30-
# $movieId: UUID!
31-
# $rating: Int!
32-
# $reviewText: String!
33-
# ) @auth(level: USER) {
16+
# mutation AddReview($movieId: UUID!, $rating: Int!, $reviewText: String!)
17+
# @auth(level: USER) {
3418
# review_upsert(
3519
# data: {
3620
# userId_expr: "auth.uid"
@@ -43,8 +27,7 @@
4327
# }
4428

4529
# # Logged in user can delete their review for a movie
46-
# mutation DeleteReview(
47-
# $movieId: UUID!
48-
# ) @auth(level: USER) {
30+
# mutation DeleteReview($movieId: UUID!) @auth(level: USER) {
31+
# # The "auth.uid" server value ensures that users can only delete their own reviews.
4932
# review_delete(key: { userId_expr: "auth.uid", movieId: $movieId })
5033
# }

templates/init/dataconnect/queries.gql

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@
1313

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

19-
# # Logged in user can list all their reviews and movie titles associated with the review
20-
# # Since the query requires the uid of the current authenticated user, the auth level is set to USER
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
2124
# query ListUserReviews @auth(level: USER) {
22-
# user(key: {id_expr: "auth.uid"}) {
25+
# user(key: { id_expr: "auth.uid" }) {
2326
# id
2427
# username
2528
# # <field>_on_<foreign_key_field> makes it easy to grab info from another table
2629
# # Here, we use it to grab all the reviews written by the user.
2730
# reviews: reviews_on_user {
28-
# id
2931
# rating
3032
# reviewDate
3133
# reviewText
@@ -50,7 +52,6 @@
5052
# description
5153
# }
5254
# reviews: reviews_on_movie {
53-
# id
5455
# reviewText
5556
# reviewDate
5657
# rating
@@ -63,16 +64,10 @@
6364
# }
6465

6566
# # Search for movies, actors, and reviews
66-
# query SearchMovie(
67-
# $titleInput: String
68-
# $genre: String
69-
# ) @auth(level: PUBLIC) {
67+
# query SearchMovie($titleInput: String, $genre: String) @auth(level: PUBLIC) {
7068
# movies(
7169
# where: {
72-
# _and: [
73-
# { genre: { eq: $genre } }
74-
# { title: { contains: $titleInput } }
75-
# ]
70+
# _and: [{ genre: { eq: $genre } }, { title: { contains: $titleInput } }]
7671
# }
7772
# ) {
7873
# id

templates/init/dataconnect/schema.gql

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,51 @@
11
# # Example schema for simple movie review app
22

3-
# # Users
4-
# # Suppose a user can leave reviews for movies
5-
# # user -> reviews is a one to many relationship,
6-
# # movie -> reviews is a one to many relationship
7-
# # movie <-> user is a many to many relationship
3+
# # User table is keyed by Firebase Auth UID.
84
# type User @table {
9-
# id: String! @col(name: "user_auth")
10-
# username: String! @col(name: "username", dataType: "varchar(50)")
11-
# # The following are generated by the user: User! field in the Review table
12-
# # reviews_on_user
13-
# # movies_via_Review
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!]!
1412
# }
1513

16-
# # Movies
14+
# # Movie is keyed by a randomly generated UUID.
1715
# type Movie @table {
18-
# # The below parameter values are generated by default with @table, and can be edited manually.
19-
# # implies directive `@col(name: "movie_id")`, generating a column name
20-
# id: UUID! @default(expr: "uuidV4()")
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()")
2119
# title: String!
2220
# imageUrl: String!
2321
# genre: String
2422
# }
2523

26-
# # Movie Metadata
27-
# # Movie - MovieMetadata is a one-to-one relationship
24+
# # MovieMetadata is a metadata attached to a Movie.
25+
# # Movie <-> MovieMetadata is a one-to-one relationship
2826
# type MovieMetadata @table {
29-
# # @unique indicates a 1-1 relationship
30-
# movie: Movie! @unique
31-
# # movieId: UUID <- this is created by the above reference
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!
3231
# rating: Float
3332
# releaseYear: Int
3433
# description: String
3534
# }
3635

37-
# # Reviews
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
3842
# type Review @table(name: "Reviews", key: ["movie", "user"]) {
39-
# id: UUID! @default(expr: "uuidV4()")
4043
# user: User!
44+
# # The user field adds the following foreign key field. Feel free to uncomment and customize it.
45+
# # userUid: String!
4146
# movie: Movie!
47+
# # The movie field adds the following foreign key field. Feel free to uncomment and customize it.
48+
# # movieId: UUID!
4249
# rating: Int
4350
# reviewText: String
4451
# reviewDate: Date! @default(expr: "request.time")

0 commit comments

Comments
 (0)