configuration makefile and dataconnect init
This commit is contained in:
8
dataconnect/example/connector.yaml
Normal file
8
dataconnect/example/connector.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
connectorId: example
|
||||
generate:
|
||||
javascriptSdk:
|
||||
- outputDir: ../../frontend-web/src/dataconnect-generated
|
||||
package: "@dataconnect/generated"
|
||||
packageJsonDir: ../../frontend-web
|
||||
react: true
|
||||
angular: false
|
||||
33
dataconnect/example/mutations.gql
Normal file
33
dataconnect/example/mutations.gql
Normal file
@@ -0,0 +1,33 @@
|
||||
# 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, insecureReason: "Any email verified users can create a new movie.") {
|
||||
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) {
|
||||
# The "auth.uid" server value ensures that users can only register their own 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) {
|
||||
# The "auth.uid" server value ensures that users can only delete their own reviews.
|
||||
review_delete(key: { userId_expr: "auth.uid", movieId: $movieId })
|
||||
}
|
||||
78
dataconnect/example/queries.gql
Normal file
78
dataconnect/example/queries.gql
Normal file
@@ -0,0 +1,78 @@
|
||||
# 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, insecureReason: "Anyone can list all movies.") {
|
||||
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 users can list all their reviews and movie titles associated with the review
|
||||
# Since the query uses the uid of the current authenticated user, we set auth level 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 {
|
||||
rating
|
||||
reviewDate
|
||||
reviewText
|
||||
movie {
|
||||
id
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Get movie by id
|
||||
query GetMovieById($id: UUID!) @auth(level: PUBLIC, insecureReason: "Anyone can get a movie by id.") {
|
||||
movie(id: $id) {
|
||||
id
|
||||
title
|
||||
imageUrl
|
||||
genre
|
||||
metadata: movieMetadata_on_movie {
|
||||
rating
|
||||
releaseYear
|
||||
description
|
||||
}
|
||||
reviews: reviews_on_movie {
|
||||
reviewText
|
||||
reviewDate
|
||||
rating
|
||||
user {
|
||||
id
|
||||
username
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Search for movies, actors, and reviews
|
||||
query SearchMovie($titleInput: String, $genre: String) @auth(level: PUBLIC, insecureReason: "Anyone can search for movies.") {
|
||||
movies(
|
||||
where: {
|
||||
_and: [{ genre: { eq: $genre } }, { title: { contains: $titleInput } }]
|
||||
}
|
||||
) {
|
||||
id
|
||||
title
|
||||
genre
|
||||
imageUrl
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user