Prisma update function fails because of incorrect type

997 views Asked by At

I am using Prisma2. The mutation function looks like this:

const updateUserProfileDetails = async (
  inputValues, ctx: { session?: SessionContext } = {}
) => {
  const profile = await db.user.update({
    where: { id: ctx.session!.userId },
    data: {
      profile: {
        update: {
          aboutMe: "this is a random message for about me.",  // type error is displayed here
          location: "London, UK", // same type error here
          profession: "rubber duck", // same type error here
        },
      },
    },
  });
  return profile;
};

However, on aboutMe, location, profession props, typescript is screaming:

Type 'string' is not assignable to type 'NullableStringFieldUpdateOperationsInput | undefined'.ts(2322)

The relevant Schema looks like this:

model User {
  id             Int       @default(autoincrement()) @id
  createdAt      DateTime  @default(now())
  updatedAt      DateTime  @updatedAt
  firstName      String?
  lastName       String?
  email          String    @unique
  hashedPassword String?
  role           String    @default("user")
  sessions       Session[]
  profile        Profile?
}

model Profile {
  id                 Int       @default(autoincrement()) @id
  aboutMe            String?
  location           String?
  profession         String?
  user               User      @relation(fields:[userId], references: [id])
  userId             Int
}

Versions:

@prisma/cli: 2.6.0 => 2.6.0 
@prisma/client: 2.6.0 => 2.6.0 

I have been unable to find (in my search through the folders), the definition of NullableStringFieldUpdateOperationsInput. What am I doing wrong?

1

There are 1 answers

0
Ryan On BEST ANSWER

Could you update @prisma/cli and @prisma/client to 2.7.1? It works fine in the latest version. I have tried it and TS doesn't complain here and the query works fine as well.

TypeScript snippet