hey morning, I've discovered Prisma yesterday and ...
# orm-help
g
hey morning, I've discovered Prisma yesterday and was impressed. There were some questions that the docs couldn't answer though. E.g. how can you restrict access to read / write database entries so that you have to be the owner of it. Let's say your blog posts.
f
That’s something you do in your backend, the business logic. Prisma is agnostic from that. Just to clarify, in general Prisma shouldn’t be called directly from the frontend, but from your backend.
👍 2
b
you can use
graphql-shield
.
🛡️ 4
👍 2
g
Ah okay, I understand. If I wanted to have a public graphql server running would my public graphql server use the prisma generated client in the resolvers?
👍 2
b
that's right. you can also use
nexus-prisma
, it will generate crud resolvers for you: https://github.com/prisma/nexus-prisma
👍 2
I was just drawing something 🙂
thx bk!
Could you still use the generated client on the front-end as well and point it to the nexus endpoint?
b
prisma client connect directly with prisma server, prisma server can parse queries from prisma client into sql queries, execute them and return result. if you point prisma client to the nexus endpoint, you have to do all the job of prisma server, so you shouldn't do that. And I'm not sure that prisma client can point to the nexus endpoint :v
n
Could you still use the generated client on the front-end as well and point it to the nexus endpoint?
That won't work because the Prisma client is not a generic "GraphQL client" (in the sense of Apollo or Relay) but it's a custom client to consume the generated API of a Prisma server. Otherwise your entire understanding is correct 🙂
Also, you drawing is spot on @Gambo 💯
g
hehe thx
okay I'm still very new to all of this. But I think I'm getting a better picture.
I haven't had a look at apollo yet and how this plays into all of that.
n
Apollo has a client and a server as well but the concepts are dissimilar from the Prisma client and Prisma server. Apollo client is to be used on the frontend (e.g. inside your React app) for fetching data from the GraphQL API. Apollo server basically is what Express.JS is in a REST API, so it's your GraphQL/HTTP layer. One architecture could be this:
Copy code
Frontend (e.g. React + Apollo Client)
↕
GraphQL server (e.g. Apollo Server + GraphQL Nexus + `nexus-prisma` + Prisma client)
↕
Prisma server
↕
Database
❤️ 4
g
okay cool. I'm starting to get an understanding
In our product we're currently using Apollo Client and express-graphql. we then have a self-written library to interact with a firestore back-end
We write everything on our own and adding a simple crud entity seems tedious