-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c1bfe2b
Showing
24 changed files
with
10,034 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
node_modules |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,18 @@ | ||
{ | ||
"name": "1", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "server.js", | ||
"scripts": { | ||
"start": "nodemon src/index.js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"graphql-cli": "^3.0.14", | ||
"graphql-yoga": "^1.18.3", | ||
"prisma-binding": "^2.3.16", | ||
"prisma-client-lib": "^1.34.10", | ||
"uuid": "^3.3.3" | ||
} | ||
} |
This file contains 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,92 @@ | ||
// prisma | ||
// .createPost({ | ||
// title: "prisma client post", | ||
// body: "hello", | ||
// published: true, | ||
// author: { | ||
// connect: { email: "[email protected]" } | ||
// } | ||
// }) | ||
// .then(console.log) | ||
// .catch(e => console.log(e)) | ||
|
||
// prisma | ||
// .createComment({ | ||
// text: "prisma client comment.", | ||
// author: { | ||
// connect: { | ||
// email: "[email protected]" | ||
// } | ||
// }, | ||
// post: { | ||
// connect: { | ||
// id: "ck338gs8t00750763f5lc0yrn" | ||
// } | ||
// } | ||
// }) | ||
// .then(console.log); | ||
|
||
const createPostForUser = async (authorId, data) => { | ||
const post = await prisma.createPost({ | ||
...data, | ||
author: { | ||
connect: {id: authorId} | ||
} | ||
}); | ||
|
||
const user = await prisma | ||
.users({ | ||
where: { | ||
id: authorId | ||
} | ||
}) | ||
.$fragment(`fragment f on users { id name email posts {id title}}`); | ||
|
||
return user; | ||
}; | ||
|
||
createPostForUser( | ||
"ck337se9y00400763sb6h2t5q", | ||
{ | ||
title: "susano post", | ||
body: "hello", | ||
published: true | ||
} | ||
).then(console.log) | ||
|
||
\\\\\\\\\\\\\\\\\\\\\\\ | ||
|
||
const updatePostForUser = async (postId, data) => { | ||
const user = await prisma.updatePost({ | ||
data: {...data}, | ||
where: { | ||
id: postId | ||
} | ||
}).author(); | ||
console.log(user); | ||
}; | ||
|
||
updatePostForUser("ck338gs8t00750763f5lc0yrn", { | ||
title: "updated post using async-await" | ||
}) | ||
//////////////////////////////// | ||
|
||
const updatePostForUser = async (postId, data) => { | ||
const postExists = await prisma.$exists.post({ id: postId }); | ||
if (!postExists) throw new Error("post not found"); | ||
|
||
const user = await prisma | ||
.updatePost({ | ||
data: { ...data }, | ||
where: { | ||
id: postId | ||
} | ||
}) | ||
.author(); | ||
|
||
console.log(user); | ||
}; | ||
|
||
updatePostForUser("ck338gs8t00750763f5lc0yrn", { | ||
title: "updated post using async-await" | ||
}).catch(err => console.log(err)); |
This file contains 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,22 @@ | ||
type User { | ||
id: ID! @id | ||
username: String! @unique | ||
reviews: [Review] @relation(name: "ReviewByUser" onDelete: CASCADE) | ||
} | ||
|
||
type Book { | ||
id: ID! @id | ||
title: String! | ||
author: String! | ||
isbn: String! @unique | ||
reviews: [Review] @relation(name: "ReviewToBook" onDelete: CASCADE) | ||
} | ||
|
||
type Review { | ||
id: ID! @id | ||
text: String | ||
rating: Int! | ||
author: User! @relation(name: "ReviewByUser" onDelete: SET_NULL) | ||
book: Book! @relation(name: "ReviewToBook" onDelete: SET_NULL) | ||
} | ||
|
Oops, something went wrong.