Hi, I am having some trouble with my Graphql serve...
# orm-help
n
Hi, I am having some trouble with my Graphql server. I want to use some types created by Prisma abstraction but I don't want to expose all the Prisma API to the client. Is there a way to import prisma models in my schema defined in the graphql server?
l
hey daniel yes use prisma-binding
import { Prisma } from 'prisma-binding' const prisma = new Prisma({ typeDefs: 'src/generated/prisma.graphql', endpoint: 'http://localhost:4466/app/folders', }) export { prisma as default }
and
import { GraphQLServer } from 'graphql-yoga' import { importSchema } from 'graphql-import' import prisma from './prisma' import { resolvers, fragmentReplacements } from './resolvers/index' const typeDefs = importSchema('./src/schema.graphql') const server = new GraphQLServer({ typeDefs, resolvers, context(req) { return { prisma, req } }, fragmentReplacements }) export { server as default }
i used docker
n
with this setup all the prisma-server api should be exposed to the client. (Correct me if I am wrong xD)
or is this the normal behaviour and all the security should be done in the graphql server layer?
l
no because my server listen to an other port and that is that port who communicate with the client
import "@babel/polyfill/noConflict" import server from './server' server.start({ port: process.env.PORT || 4000 }, () => { console.log('server listening') })
and yes you have to do all the security
also
n
but
src/generated/prisma.graphql
don't have all the prisma api? If you use the prisma.graphql in the graphql server, won't it expose all the api and datamodels to the client?
I am new to graphql and prisma. Sorry if I am doing some dumb misundersting hahaha
l
prisma api is no secure at all you have to do this graphql server with node is a layer to hash password, block user etc...
you have to do security in your resolvers
n
I got this point, I just don't want anyone that access the graphql server to have access to all the datamodels and api functions.
l
you can't reach your prisma directly on graphqlserver you have to use resolvers
to get the parameter from prisma
you parameter what you want from the api with the model i sent you
but the client does not have access to prisma api
i dont know if im clear
n
ah... I got it... I was trying to merge some schemas importing some
prisma.graphql
type in my
schema.graphql
. But it seems that they have to be different implementations... otherwise I would be exposing my datamodel anyway
l
ok nice 🙂 the way i model it is => you just call prisma when you want to use it in your resolvers but there is no way to the client to access to it
n
Thanks lucas! 👍
👍 1
f
@Naka You can import types from the generated Prisma schema to your app schema by using
graphql-import
. Something like
#import Post from "../generated/prisma.graphql"
, and it should only import
Post
type. Then you can use it in your app schema as you want.