Disconnect array of nodes

prisma

#1

Hey, I’m looking to disconnect nodes on an update mutation, is it possible to do this when it’s an array of nodes?

Disconnect works perfectly when I have a single node, e.g:

activeClass: {
   disconnect: true
},

Where active class in a single node, however, if I had:

activeClasses: {
   disconnect: true
},

Where active classes is an array I get the following error

Type 'boolean' is not assignable to type

Thanks!


#2

I don’t understand your code snippets.
Can you share your datamodel and the entire mutation? :slightly_smiling_face:


#3

Hi @nilan,

Sure thing!

Datamodel:

type Programme {
  id: ID! @unique
  title: String! @unique
  lowerTitle: String! @unique
  description: String
  heroImage: File

  weeks: [ProgrammeWeek!]! @relation(name: "ProgrammeWeek")
  classes: [ProgrammeClass!]! @relation(name: "ClassesInProgramme")
  users: [ProgrammeUser!]! @relation(name: "ProgrammeUserProgramme")
}

type ProgrammeWeek {
  id: ID! @unique
  classes: [ProgrammeClass!]!
  programme: Programme! @relation(name: "ProgrammeWeek")

  title: String
  description: String
  number: Int!
}

type ProgrammeClass {
  id: ID! @unique
  class: Class!
  week: [ProgrammeWeek!]!
  programme: [Programme!]! @relation(name: "ClassesInProgramme")
  completedBy: [ProgrammeUser!]! @relation(name: "CompletedBy")
  activeOn: [ProgrammeUser!]! @relation(name: "ActiveOn")
  active: Boolean! @default(value: "true")
}

type ProgrammeUser {
  id: ID! @unique
  user: User! @relation(name: "ProgrammeOnUser")
  programme: Programme! @relation(name: "ProgrammeUserProgramme")
  active: Boolean!
  activeWeek: ProgrammeWeek
  activeClass: ProgrammeClass @relation(name: "ActiveOn")
  completedClasses: [ProgrammeClass!]! @relation(name: "CompletedBy")
  startDate: DateTime
  count: Int
}

In my case I’m trying to disconnect completedClasses when a ProgrammeUser is marked as active: false.

Mutations:

This one works fine:

return await ctx.db.mutation.updateProgrammeUser({
        where: {
          id
        },
        data: {
          active: false,
          activeClass: {
            disconnect: true,
          },
        },
      });

However, this one gives the error:

return await ctx.db.mutation.updateProgrammeUser({
        where: {
          id
        },
        data: {
          active: false,
          activeClass: {
            disconnect: true,
          },
         completedClasses: {
            disconnect: true,
          }
        },
      });

Here’s the full ts warning:

[ts]
Argument of type '{ where: { id: any; }; data: { active: boolean; activeClass: { disconnect: boolean; }; completedC...' is not assignable to parameter of type '{ data: ProgrammeUserUpdateInput; where: ProgrammeUserWhereUniqueInput; }'.
  Types of property 'data' are incompatible.
    Type '{ active: boolean; activeClass: { disconnect: boolean; }; completedClasses: { disconnect: boolean...' is not assignable to type 'ProgrammeUserUpdateInput'.
      Types of property 'completedClasses' are incompatible.
        Type '{ disconnect: boolean; }' is not assignable to type 'ProgrammeClassUpdateManyWithoutCompletedByInput'.
          Types of property 'disconnect' are incompatible.
            Type 'boolean' is not assignable to type 'ProgrammeClassWhereUniqueInput | ProgrammeClassWhereUniqueInput[]'.

Appreciate the help!


#4

You can disconnect multiple nodes like:
disconnect: [{id:"ID1"}, {id:"ID2"},...etc]


#5

Ah! That makes perfect sense, thanks @Huvik!