hey all, i’m, having a many to many relationship b...
# orm-help
g
hey all, i’m, having a many to many relationship between
Branches
and
Labels
i’m trying to write a mutation to add a branch to a label.
Copy code
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
Copy code
model Label {
  id        String    @id @default(cuid())
  name      String    @unique
  branches  Branch[]
  createdAt DateTime? @default(now())
}