random question if I'm using the mongo db piece wi...
# orm-help
b
random question if I'm using the mongo db piece with prisma I'm assuming I have to host my own prisma right since it appears your server service via heroku and such only supports mysql and postgres right? Not a big deal was just curious I have it setup in docker so it wouldn't be that hard to put nginx in front of it for SSL and connect it to the prisma console securely
j
I would really recommend having a layer between Prisma and the 'outside world' and do the auth in there. Then you can put nginx (or similar solutions) in front of that layer and do SSL-termination there.
k
Something like graphql-yoga?
j
Yes, exactly like graphql-yoga (which is very nice and easy to use) or apollo-server or express-graphql or any of the other solutions available. I can recommend, since you're already using Prisma, to have a look at nexus-prisma and graphql-nexus (in conjunction with the others).
k
That's a new thing, so nexus-prisma and graphql-nexus, are these replacements and/or add-ons to prisma and yoga? A brief overview would be appreciated as I'm about to start a project and am actively looking for graphql integrations.
b
I already have graphql yoga as my backend
but I thought I still needed prisma with graphql yoga from my understanding
right now I have prisma setup with yoga tied to mongodb as the db and was just curious when I take this to prod I'm assuming the best option is to do cloud hosted mongo, then host my backend with prisma and yoga on it and connect that to the prisma console or am I missing something?
j
@Kapil Sharma
graphql-nexus
and
nexus-prisma
is a way of generating the schema code-first. Can recommend reading this series: https://www.prisma.io/blog/using-graphql-nexus-with-a-database-pmyl3660ncst/. @btotharye That sounds like what I'd do. Just make sure that you give it the correct connection string in it's configuration 🙂
🤠 1
👍 1
b
So my current dev process is: 1. Spin up the docker compose setup which is my local prisma with mongodb containers. 2. Then I do a npm run dev atm haven't moved it to a container yet to spin up yoga and my backend auth stuff, etc that uses graphql. My frontend then talks to this respective backend graphql running at port 4444 for example
j
Sounds solid.
b
ok so I think basically this current compose file for dev:
Copy code
version: "3"
services:
  prisma:
    image: prismagraphql/prisma:1.26
    restart: always
    ports:
      - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        databases:
          default:
            connector: mongo
            uri: mongodb://${MONGO_USER}:${MONGO_PW}@mongo
  mongo:
    image: mongo:3.6
    restart: always
    env_file:
      - .env
    volumes:
      - mongo:/var/lib/mongo
    ports:
      - "27017:27017"
volumes:
  mongo:
would basically just become the prisma only and my backend basically and then nginx would sit in front for SSL and I could then use that https endpoint to connect it to prisma console right?
and the mongo piece would obviously become my hosted mongo uri
seems like the right approach its been working pretty solid in local dev so far
j
I think so too.
b
basically my backend just supplements the existing graphql stuff so it has more options for the signin mutations, etc
building a system to track snakes and such since I do that on the side 🙂
🐍 1
j
Yeah. I would probably also look into graphql-shield to protect parts of your schema that you don't want to give unrestricted access to. The 'native' Prisma bindings are very powerful.
b
ok I'll check it out, atm I just have permissions setup in the schema and use that
so all endpoints require auth and some mutations/queries require certain permissions I handle it on the backend
j
You can do that as well! 🙂 If you want to see an example of how I solved authentication with graphql-nexus (nexus-prisma) and graphql-shield there's an example I've written under the graphql-shield examples on github.
b
I do have to say though prisma makes making a graphql api a breeze I hate having to use pymongo and crap
ok cool I'll look at that
this is just for the beta I'm launching soon so it can always change over time
j
Prisma is ❤️ and, imho, graphql-nexus made it even easier.
b
it may also be janky but lately I've been testing when I add new types to a schema that was already there I'm not making it required and handling that with validation on frontend/backend
at least so I don't run into issues where it complains cause I already have records
trying to simulate real world when its out there with data on it and I want to update stuff
j
What you can also do is make new required values have a 'default' tag so that it gets a default value. On your next migration you can remove the tag again.
b
yea I've been playing with that too
its great for booleans where it needs something
I'm looking at the nexus stuff now, I was using graphql tag to make my queries and such
j
nexus-prisma allowed me to bootstrap a graphql server and schema with all prisma queries and custom mutations in about 10 minutes.
b
yea I need to see how that is different from what I'm doing with yoga, typically right now I just do the prisma init, then update my file and use yoga to serve it basically seems interesting