Hi Guys, Just started using Prisma, loving it so f...
# orm-help
m
Hi Guys, Just started using Prisma, loving it so far. I found the following article https://www.prisma.io/blog/graphql-directive-permissions-authorization-made-easy-54c076b5368e/ on how to add authorization to fields and mutation, how should i implement this with auto generated mutations? for example updatePost = admin only?
l
Hi Max, welcome! Can you explain what you mean by "auto generated mutation?" I'm going to assume you mean the Prisma mutations. Prisma is designed to sit behind an application server (save for very specific use cases). The article focuses on how to secure the application server, not Prisma itself. Prisma is secured by tokens and sitting behind the application server.
m
@lawjolla Thanks for your answer, so you’re saying that the prisma mutation won’t work if an user would send these to the public graphql endpoint of my nodeserver?
For example I haven’t defined a posts() query, if i fire { posts { id } } in http://localhost:3000/playground, it works
l
That's right because your're accessing Prisma directly
m
That makes sense, would be a huge security risk otherwise. Thanks
l
Are you worried that others may have direct Prisma access? If so, you'll want to make sure it has a security token. For instance, when I access my Prisma's playground, I have to keep giving it a Bearer token
m
No, I was worried all the prisma generated queries/mutations we’re accessible on the public endpoint 🙂
l
Gotcha. By default, nothing is available. You have to make the types and/or import them (see
graphql-import
) and make the corresponding resolvers
m
Thanks, it all makes sense now 🙂
👍 1
i
If you want to access Prisma directly, just use forwarding
There is an example on forwarding in Prisma repo
👍 1
But the base idea is that you write in schema your
updatePost
mutation, write it in resolvers with
forwardTo
, and it will call an auto generated method from Prisma
Then you just add shield to it
m
awesome that reduces boilerplate 🙂