ive been trying to do it myself just not good enou...
# orm-help
d
ive been trying to do it myself just not good enough yet, still learning
r
Hey @DeanMo 👋 Did you try this tutorial out?
d
Yeah, few times. Just need to retackle it all mentally. I have done the tutorials on prisma.io, nexusjs.org howtographql.com and various other places. Its just confusing a bit coming from little experience. I have taken a few day break from things and will be tacking stuff again tonight but. I spoke a bit with ryanchenkie about where i am at with everything, he helped me out for sure. I can see the benefits of using prisma, nexus and graphql together, but then it gets confusing as a new person where everything starts and stops its control. Ryan helped me out with a few of the mental blocks I was having there. Now I am working on trying to get prisma/nexus/graphql working with quasar, which is a vue framework, and having some difficulties there. Seems like I need to learn apollo to make it work, then that becomes more confusing. I probably am just a moron so, do not mind me. All around though I think it would be nice to have a nexus/prisma interpretation of the howtographql tutorial. I think that goes a bit farther in depth than the prisma and nexus tutorials on their own and combined. I have also been going through the example repo's trying to piece it together mentally, just again, some odd mental block.
💯 1
I usually pick stuff up pretty damn fast so not sure why this is such an issue for me. I am rereading the orig graphql docs, did stuff on udemy for graphql, i read about it and try to learn a bunch. Just think coming from very little sql experience, very little back end experience, and having everythign upgrading and updating all at the same time makes it rough.
If you were to go on youtube right now, and type in nexus prisma
there is not much content. You get some stuff from a guy named corey, 5 videos from last year. Then there is the 1 video from prismaday this year, uploaded just a few weeks ago.
Maybe an avenue there for some content creator, or you guys to fill in if you wanted.
👍 1
Ahh I guess I missed this here too.

https://www.youtube.com/watch?v=XITMliBUDXU

so thats the only 3 sources of content for nexus/prisma on youtube, and 1 of which is outdated.
I have no issues reading docs, and i actually enjoy doing so, but visual learning helps alot too.,
Again though, I can see why using all of this is a very useful and valid thing, so I am still working at it, and again, it is most likely just me being a moron 😄
If I showed you the amount of repos I have started in the last month.....graphql-nexus, graphql-nexus-restart, graphql-nexus-rerestart, nexus-prisma, hackernews-nexus, hackernews-nexus-attempt1
😄
# nexustoprisma mkdir nexustoprisma cd nexustoprisma npm init -y npm install typescript ts-node @types/node --save-dev npm install nexus nexus-plugin-prisma package.json
Copy code
"scripts": {
  "nexus dev": "nexus dev",
  "nexus build": "nexus build"
}
tsconfig.json
Copy code
{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "lib": [
      "esnext"
    ],
    "strict": true,
    "rootDir": "api",
    "noEmit": true,
    "plugins": [
      {
        "name": "nexus/typescript-language-service"
      }
    ],
    "typeRoots": [
      "node_modules/@types",
      "types"
    ]
  },
  "include": [
    "types.d.ts",
    "api"
  ]
}
.vscode/launch.json
Copy code
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Debug Nexus App",
      "protocol": "inspector",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nexus",
      "runtimeArgs": [
        "dev"
      ],
      "sourceMaps": true,
      "console": "integratedTerminal"
    }
  ]
}
npx prisma npx prisma init nexustoprisma/prisma/.env
Copy code
DATABASE_URL="<postgresql://NAME:NAME@localhost:5432/DBNAME?schema=public>"
open pgadmin, create nexustoprisma mkdir api api/app.ts
Copy code
import { use } from 'nexus'
import { prisma } from 'nexus-plugin-prisma'

use(
	prisma({
		features: {
			crud: true,
		},
	})
)
nexustoprisma/prisma/schema.prisma
Copy code
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model Employee {
  id           String      @default(uuid()) @id
  name         String
  email        String      @unique
  photo_url    String?
  createdAt    DateTime    @default(now())
  updatedAt    DateTime    @updatedAt
  status       Boolean     @default(false)
  employer     Employer?   @relation(fields: [employerID], references: [id])
  employerID   String?
}

model Employer {
  id           String       @default(uuid()) @id
  name         String
  email        String       @unique
  photo_url    String?
  createdAt    DateTime     @default(now())
  updatedAt    DateTime     @updatedAt
  employees    Employee[]
}
npx prisma migrate save --experimental npx prisma migrate up --experimental npx prisma generate Generate data with seed.js prisma/seed.js
Copy code
const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()

const main = async () => {
	let employees = [
		'Julio', 'Dante', 'Emily',
		'Willis', 'Flanders', 'Don',
		'Denise', 'Rasheed', 'Anna',
	]

	let employers = ['Brock', 'Chad', 'Dave']
	for (const employer of employers) {
		employerList = await prisma.employer.create({
			data: {
				name: `${employer}`,
				email: `${employer}@employerTest.com`,
			},
		})
		console.log(employerList)
	}

	const empSeed = await prisma.employer.findMany()

	for (const [index, emp] of employees.entries()) {
		employeeList = await prisma.employee.create({
			data: {
				name: `${emp}`,
				email: `${emp}@test.com`,
				employer: {
					connect: { id: empSeed[index % employers.length].id },
				},
			},
		})
		console.log(employeeList)
	}
}

main()
	.catch(e => console.error(e))
	.finally(async () => {
		await prisma.disconnect()
	})
index.ts
Copy code
import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function main() {
	const allEmployees = await prisma.employee.findMany()
	console.log(allEmployees)
}

main()
	.catch(e => {
		throw e
	})
	.finally(async () => {
		await prisma.disconnect()
	})
api/graphql/Employee.ts
Copy code
import { schema } from 'nexus'

schema.objectType({
    name: 'Employee',
    description: 'Employee for the company',
    definition(t) {
        t.model.id()
        t.model.name()
        t.model.email()
        t.model.photo_url()
        t.model.createdAt()
        t.model.updatedAt()
        t.model.status()
        t.model.employerID()
    }
})
api/graphql.Employer.ts
Copy code
import { schema } from 'nexus'

schema.objectType({
	name: 'Employer',
	description: 'Employer of the company',
	definition(t) {
		t.model.id()
		t.model.name()
		t.model.email()
		t.model.photo_url()
		t.model.createdAt()
    t.model.updatedAt()
	},
})
api/graphql/Mutation.ts
Copy code
import { schema } from 'nexus'

schema.mutationType({
	definition(t) {
		t.crud.createOneEmployee()
		t.crud.createOneEmployer()
		t.crud.deleteOneEmployee()
		t.crud.deleteManyEmployee()
		t.crud.deleteOneEmployer()
    t.crud.deleteManyEmployer()
    t.crud.updateOneEmployee()
    t.crud.updateManyEmployee()
    t.crud.updateOneEmployer()
    t.crud.updateManyEmployer()
	},
})
this is my write up i did for how to get to where i usually shit out mentally.
working with ryanchenkie i kinda narrowed it down to resolvers, and nexus. using .crud feature or not and how it is optional. Getting closer.... just need to keep at it.
the above was me trying to redo the cory videos from youtube with prisma1 and old nexus using the new updated stuff
shit out right around here every time
n
Chiming in here as well 😄 We're definitely planning a Nexus tutorial for How to GraphQL, we don't have a concrete timeline at the moment but hopefully we'll get to it soon. Also, if you're looking for more video content, I recently gave a talk where I built a Nexus GraphQL API from scratch – maybe that makes a few things more clear as well?

https://youtu.be/AnJxKWQG_fM?t=1315

💯 1
d
oh nice!
I will go through this video also, I really want to have prisma/nexus be the thing I rely upon so trying to build the foundation up strong. I am just self taught with no prior experience beyond 4 months of every day work so.
👍 2
I will say how the people at prisma/nexus work, and interact with the community is like next to none. You all swoop in to help when anyone needs it and I give praise and applaud to you for that.
🙌 2
The more people using this easily, the more yall benefit which I understand, but most companies/conglomerates do not get that.
a
@DeanMo Check out this playlist by the Prisma people. Especially the last two videos in the series.

https://www.youtube.com/watch?v=XM57Yi3dVjU&amp;list=PLn2e1F9Rfr6lg1b53s36v--OSWrYKvskI