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())
}