Skip to content

Commit

Permalink
integrating prisma to resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
jeancarlos-cpu committed Nov 17, 2019
0 parents commit c1bfe2b
Show file tree
Hide file tree
Showing 24 changed files with 10,034 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5,341 changes: 5,341 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions package.json
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"
}
}
92 changes: 92 additions & 0 deletions prisma-client-tests.txt
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));
22 changes: 22 additions & 0 deletions prisma-review-website/datamodel.prisma
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)
}

Loading

0 comments on commit c1bfe2b

Please sign in to comment.