glekner
08/04/2021, 10:13 PMBranches
and Labels
i’m trying to write a mutation to add a branch to a label.
t.field('addBranchToLabel', {
type: 'Label',
args: {
data: nonNull(
arg({
type: 'LabelAddBranchCreateInput',
}),
),
},
resolve: async (_parent, { data }, ctx) => {
const branch = await ctx.prisma.branch.findUnique({
where: {
id: data.branchId,
},
})
if (!branch) {
throw new Error('Invalid Branch')
}
const label = await ctx.prisma.label.findUnique({
where: {
name: data.labelName,
},
})
if (!label) {
throw new Error('Invalid Label')
}
console.log('label', label)
return ctx.prisma.label.update({
where: { name: label.name },
data: {
branches: {
connectOrCreate: [
{
where: {
id: data.branchId,
},
create: branch,
},
],
},
},
})
},
})
the mutation works, but when I query the branches list of the label, it returns null
, so the branch wasnt added.
any help?
here is the model
model Label {
id String @id @default(cuid())
name String @unique
branches Branch[]
createdAt DateTime? @default(now())
}
Ivan Jeremic
08/04/2021, 10:20 PMglekner
08/04/2021, 10:38 PMhttps://prisma.slack.com/archives/CA491RJH0/p1628115202140400I do see the branches in Prisma studio
glekner
08/04/2021, 10:39 PMglekner
08/04/2021, 10:39 PMglekner
08/04/2021, 10:56 PMcontext.prisma.label.findMany({ include: { branches: true } })
Oluwasetemi Ojo
08/05/2021, 8:30 AMDavid
08/05/2021, 11:32 AMruntime
folder went missing in prisma folder inside node_modules?David
08/05/2021, 11:32 AMconst dirname = findSync(process.cwd(), [
^
TypeError: findSync is not a function
David
08/05/2021, 11:33 AMnode_modules/.prisma/client/index.js:55
I found it like this, but the runtime folder isn't exist.David
08/05/2021, 11:36 AM@prisma
, the runtime folder is exist, but not the findSync
user
08/05/2021, 5:02 PMDaniel Olavio Ferreira
08/05/2021, 8:17 PMconst commentParser = (comments: Comment[]): Comment[] => {
const commentMap = {};
comments.forEach((comment) => {
commentMap[comment.id] = comment;
commentMap[comment.id].children = [];
});
comments.forEach((comment) => {
if (comment.parentId !== null) {
const parent = commentMap[comment.parentId];
parent.children.push(comment);
}
});
return comments.filter((comment) => comment.parentId === null);
};
The income data looks like this:
[
{
id: 'ckryupa4i0014sdyazioetibq',
text: 'Teste',
createdAt: '05/08/2021',
parentId: 'ckryqxk8s02772zyagi476b6x'
},
{
id: 'ckryvgpd80063sdyadwo9gyck',
text: 'Teste 2',
createdAt: '05/08/2021',
parentId: 'ckryupa4i0014sdyazioetibq'
},
{
id: 'ckryr0tgh03352zya03qkogtx',
text: 'You are welcome',
createdAt: '05/08/2021',
parentId: 'ckryqw59k02432zyaet0j395g'
},
{
id: 'ckryqxk8s02772zyagi476b6x',
text: 'dasdasd',
createdAt: '05/08/2021',
parentId: null
},
{
id: 'ckryqw59k02432zyaet0j395g',
text: 'Thanks!',
createdAt: '05/08/2021',
parentId: 'ckryp56ga00492zya3yq6kgbm'
},
{
id: 'ckryp56ga00492zya3yq6kgbm',
text: 'great post!',
createdAt: '05/08/2021',
parentId: null
}
]
Here is my Comment model:
model Comment {
id String @id @default(cuid())
text String
createdAt DateTime @default(now()) @map("created_at")
author User @relation(fields: [authorId], references: [id])
authorId String @map("author_id")
post Post @relation(fields: [postId], references: [id])
postId String @map("post_id")
children Comment[] @relation("CommentToComment")
parent Comment? @relation("CommentToComment", fields: [parentId], references: [id])
parentId String?
}
Carlos Gomez
08/05/2021, 8:50 PMseed.ts
file and prisma db seed --preview-feature
. Is it possible to invoke the seed with parameters? Possibly passed via env vars?
Edit: working sample in thread.Gelo
08/06/2021, 6:16 AMEvan
08/06/2021, 2:02 PMPrisma schema loaded from prisma/schema.prisma
Error: binaryTargets.flatMap is not a function
How I got to this is i renamed a model that had two many to many relationships to a different name. Maybe there’s a better way if I need to rename an entire table besides just renaming it in the schema file and re-running migration/generate? 😅Jonas
08/06/2021, 2:19 PMasync function reset() {
awais table1.deleteMany({})
awais table2.deleteMany({})
}
Jonas
08/06/2021, 2:20 PMJonas
08/06/2021, 2:20 PMfor (const {
tablename,
} of await prismaClient.$queryRaw`SELECT tablename FROM pg_tables WHERE schemaname='public'`) {
if (tablename !== '_prisma_migrations') {
try {
await prismaClient.$queryRaw(`TRUNCATE TABLE "public"."${tablename}" CASCADE;`)
} catch (error) {
console.log({ error })
}
}
}
Jonas
08/06/2021, 2:20 PMJonas
08/06/2021, 2:21 PMJonas
08/06/2021, 2:21 PMMykyta Machekhin
08/06/2021, 3:57 PMHalvor
08/06/2021, 10:05 PMmodel StatGamemode {
id Int @id @default(autoincrement())
type Gamemode
matches_played Int @default(0)
statGamemodeDM StatGamemodeDM?
}
model StatGamemodeDM {
id Int @id @default(autoincrement())
statGamemode StatGamemode @relation(fields: [statGamemodeId], references: [id])
statGamemodeId Int
kills Int @default(0)
}
And my old query only summerizing the columns in StatGamemode looks like this:
const result = await prisma.statGamemode.aggregate({
_count: {
_all: true
},
_sum: {
matches_played: true,
//kills: true
},
where: {
type: gamemode
}
});
How can i summerize the "kills" column from StatGamemodeDM table in the same query?Temm
08/06/2021, 11:18 PMprisma db push
2 being prisma migrate dev
but this doesnt seem to be the case: when running 2 locally, it warns me that database drift has been detected, and it will have to reset my database
Can someone help with this?
What is the correct way of doing this?Gelo
08/07/2021, 3:21 AMGelo
08/07/2021, 3:21 AMOrigin
08/07/2021, 9:01 PMOrigin
08/07/2021, 9:02 PMNathaniel Babalola
08/08/2021, 1:10 AMProvided List<Json> , expected yyyCreateNestedManyWithoutxxxInput
How do I fix this please?