Is there a reason that an update operation throws ...
# orm-help
k
Is there a reason that an update operation throws a type error on the data parameter when a field that is required in the prisma schema is not present? This makes sense for a create operation, but an update could just be updating a single field, in which case the extra fields would not be necessary. How's everyone else handling this, are you passing an entire row of data, just to update a single field?
j
If I understand correctly, you want to update something but it throws u an error because u don't want that to update that argument(s)?
k
Basically I have a mutation where I call update on a model.
Copy code
return prisma.player.update({ where: { id: playerToUpdate }, data: args.data });
Typescript doesn't like the data argument because the type of args.data has fields that could be undefined, but which are required in the Player schema
j
p.field("updateProfile", {
     
type: "profile",
     
args: {
       
profileID: idArg(),
       
firstname: stringArg(),
       
lastname: stringArg(),
       
phone: PhoneNumberResolver,
     
},
     
resolve: async (
       
_,
       
{ profileID, firstname, lastname, phone }: any
     
): Promise<any> => {
       
const profile = await prisma.profile.update({
         
where: { profileID },
         
data: {
           
firstname,
           
lastname,
           
phone,
         
},
       
});
       
pubsub.publish("updatedProfile", profile);
       
return profile;
     
},
   
});
try like that
k
I don't see how that makes a difference.
j
can u send the update mutation so I can replicate
k
Copy code
export const UpdatePlayerInput = inputObjectType({
  name: 'UpdatePlayerInput',
  definition (t) {
    t.string('firstName');
    t.string('lastName');
    t.dateTime('dateOfBirth');
    t.string('jerseySize');
    t.string('userRelationShip');
  },
});
Copy code
export const UpdatePlayer = mutationField('updatePlayer', {
  type: PlayerType,
  args: {
    id: nonNull(stringArg()),
    data: UpdatePlayerInput,
  },
  resolve (_root, { id, data }, { session, prisma }) {
    return prisma.player.update({ where: { id: id }, data });
  },
});
j
convert it into your mutation field, if I am not mistaken I already did this on my first web project
k
@Joshua Ramin Thanks for your time and help. I figured it out. Turns out I had a field on my UpdatePlayerInput that I told it was a string and it was actually an ENUM. Of course the type error can't give anywhere near helpful output.
💯 1