Skip to content

Commit

Permalink
Merge branch 'adding-data-connect'
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisAlund committed Oct 17, 2024
2 parents 5d567e8 + 63d1c43 commit a27bb02
Show file tree
Hide file tree
Showing 19 changed files with 2,184 additions and 2,874 deletions.
3 changes: 3 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"apphosting",
"Buildable",
"clsx",
"codegen",
"dataconnect",
"datepicker",
"firebaseui",
"firestore",
Expand All @@ -14,6 +16,7 @@
"grantaccess",
"linebreak",
"lowlight",
"oddbit",
"satoshi",
"tanam",
"tiptap",
Expand Down
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"nrwl.angular-console",
"esbenp.prettier-vscode",
"ms-playwright.playwright",
"firsttris.vscode-jest-runner"
"firsttris.vscode-jest-runner",
"googlecloudtools.firebase-dataconnect-vscode"
]
}
11 changes: 7 additions & 4 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"remoteconfig": {
"template": "remoteconfig.template.json"
},
"dataconnect": {
"source": "libs/dataconnect/src"
},
"functions": [
{
"source": "apps/cloud-functions",
"source": "dist/apps/cloud-functions",
"runtime": "nodejs20",
"codebase": "tanam",
"ignore": [
Expand Down Expand Up @@ -61,8 +67,5 @@
"enabled": true
},
"singleProjectMode": true
},
"remoteconfig": {
"template": "remoteconfig.template.json"
}
}
18 changes: 18 additions & 0 deletions libs/dataconnect/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
1 change: 1 addition & 0 deletions libs/dataconnect/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/
5 changes: 5 additions & 0 deletions libs/dataconnect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# dataconnect

This library contains the [Firebase Dataconnect](https://firebase.google.com/docs/data-connect) definitions.

Make sure to generate the SDKs before building any app code that depends on it: `nx codegen dataconnect`
11 changes: 11 additions & 0 deletions libs/dataconnect/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: "dataconnect",
preset: "../../jest.preset.js",
testEnvironment: "node",
transform: {
"^.+\\.[tj]s$": ["ts-jest", {tsconfig: "<rootDir>/tsconfig.spec.json"}],
},
moduleFileExtensions: ["ts", "js", "html"],
coverageDirectory: "../../coverage/libs/dataconnect",
};
30 changes: 30 additions & 0 deletions libs/dataconnect/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "dataconnect",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/dataconnect/src",
"projectType": "library",
"tags": [
"lib:backend",
"lib:frontend"
],
"targets": {
"build": {
"executor": "nx:noop"
},
"e2e": {
"executor": "nx:noop"
},
"test": {
"executor": "nx:noop"
},
"lint": {
"executor": "nx:noop"
},
"codegen": {
"executor": "nx:run-commands",
"options": {
"command": "firebase dataconnect:sdk:generate"
}
}
}
}
6 changes: 6 additions & 0 deletions libs/dataconnect/src/connector/connector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
connectorId: default
generate:
javascriptSdk:
outputDir: ../../lib/js
package: "@tanam/dataconnect"
packageJsonDir: ../../../..
50 changes: 50 additions & 0 deletions libs/dataconnect/src/connector/mutations.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# # Example mutations for a simple movie app

# # Create a movie based on user input
# mutation CreateMovie(
# $title: String!
# $genre: String!
# $imageUrl: String!
# ) @auth(level: USER_EMAIL_VERIFIED) {
# movie_insert(
# data: {
# title: $title
# genre: $genre
# imageUrl: $imageUrl
# }
# )
# }

# # Upsert (update or insert) a user's username based on their auth.uid
# mutation UpsertUser($username: String!) @auth(level: USER) {
# user_upsert(
# data: {
# id_expr: "auth.uid"
# username: $username
# }
# )
# }

# # Add a review for a movie
# mutation AddReview(
# $movieId: UUID!
# $rating: Int!
# $reviewText: String!
# ) @auth(level: USER) {
# review_upsert(
# data: {
# userId_expr: "auth.uid"
# movieId: $movieId
# rating: $rating
# reviewText: $reviewText
# # reviewDate defaults to today in the schema. No need to set it manually.
# }
# )
# }

# # Logged in user can delete their review for a movie
# mutation DeleteReview(
# $movieId: UUID!
# ) @auth(level: USER) {
# review_delete(key: { userId_expr: "auth.uid", movieId: $movieId })
# }
83 changes: 83 additions & 0 deletions libs/dataconnect/src/connector/queries.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# # Example queries for a simple movie app.

# # @auth() directives control who can call each operation.
# # Anyone should be able to list all movies, so the auth level is set to PUBLIC
# query ListMovies @auth(level: PUBLIC) {
# movies {
# id
# title
# imageUrl
# genre
# }
# }

# # List all users, only admins should be able to list all users, so we use NO_ACCESS
# query ListUsers @auth(level: NO_ACCESS) {
# users { id, username }
# }

# # Logged in user can list all their reviews and movie titles associated with the review
# # Since the query requires the uid of the current authenticated user, the auth level is set to USER
# query ListUserReviews @auth(level: USER) {
# user(key: {id_expr: "auth.uid"}) {
# id
# username
# # <field>_on_<foreign_key_field> makes it easy to grab info from another table
# # Here, we use it to grab all the reviews written by the user.
# reviews: reviews_on_user {
# id
# rating
# reviewDate
# reviewText
# movie {
# id
# title
# }
# }
# }
# }

# # Get movie by id
# query GetMovieById($id: UUID!) @auth(level: PUBLIC) {
# movie(id: $id) {
# id
# title
# imageUrl
# genre
# metadata: movieMetadata_on_movie {
# rating
# releaseYear
# description
# }
# reviews: reviews_on_movie {
# id
# reviewText
# reviewDate
# rating
# user {
# id
# username
# }
# }
# }
# }

# # Search for movies, actors, and reviews
# query SearchMovie(
# $titleInput: String
# $genre: String
# ) @auth(level: PUBLIC) {
# movies(
# where: {
# _and: [
# { genre: { eq: $genre } }
# { title: { contains: $titleInput } }
# ]
# }
# ) {
# id
# title
# genre
# imageUrl
# }
# }
12 changes: 12 additions & 0 deletions libs/dataconnect/src/dataconnect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
specVersion: "v1beta"
serviceId: "tanam"
location: "us-central1"
schema:
source: "./schema"
datasource:
postgresql:
database: "fdcdb"
cloudSql:
instanceId: "tanam-fdc"
# schemaValidation: "COMPATIBLE"
connectorDirs: ["./connector"]
45 changes: 45 additions & 0 deletions libs/dataconnect/src/schema/schema.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# # Example schema for simple movie review app

# # Users
# # Suppose a user can leave reviews for movies
# # user -> reviews is a one to many relationship,
# # movie -> reviews is a one to many relationship
# # movie <-> user is a many to many relationship
# type User @table {
# id: String! @col(name: "user_auth")
# username: String! @col(name: "username", dataType: "varchar(50)")
# # The following are generated by the user: User! field in the Review table
# # reviews_on_user
# # movies_via_Review
# }

# # Movies
# type Movie @table {
# # The below parameter values are generated by default with @table, and can be edited manually.
# # implies directive `@col(name: "movie_id")`, generating a column name
# id: UUID! @default(expr: "uuidV4()")
# title: String!
# imageUrl: String!
# genre: String
# }

# # Movie Metadata
# # Movie - MovieMetadata is a one-to-one relationship
# type MovieMetadata @table {
# # @unique indicates a 1-1 relationship
# movie: Movie! @unique
# # movieId: UUID <- this is created by the above reference
# rating: Float
# releaseYear: Int
# description: String
# }

# # Reviews
# type Review @table(name: "Reviews", key: ["movie", "user"]) {
# id: UUID! @default(expr: "uuidV4()")
# user: User!
# movie: Movie!
# rating: Int
# reviewText: String
# reviewDate: Date! @default(expr: "request.time")
# }
16 changes: 16 additions & 0 deletions libs/dataconnect/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs"
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
11 changes: 11 additions & 0 deletions libs/dataconnect/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
9 changes: 9 additions & 0 deletions libs/dataconnect/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
}
5 changes: 5 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
}
],
"targetDefaults": {
"lint": {
"dependsOn": [
"codegen"
]
},
"build": {
"dependsOn": ["lint", "^lint", "^build"]
},
Expand Down
Loading

0 comments on commit a27bb02

Please sign in to comment.