PrismaClientValidationError: Argument is missing - How to resolve? #20216
Replies: 7 comments 6 replies
-
Hi @delfincortesb 👋 Thank you for raising this question.
Can you please clarify if you are trying to include the const res = await prisma.documents_counter.update({
where:{
company_id: 2,
},
data:{
estimate_count: {
increment: 1,
},
},
include: {
companies: true
}
}) Or are you trying to perform a nested update on the companies relation as shown in the code snippet below: const res = await prisma.documents_counter.update({
where:{
company_id: 2,
},
data:{
estimate_count: {
increment: 1,
},
companies:{
create:{
name:"test",
username:"gab",
}
}
},
}) |
Beta Was this translation helpful? Give feedback.
-
This bug still happening to me. |
Beta Was this translation helpful? Give feedback.
-
+1, When I accidentally try to set a non-null field to |
Beta Was this translation helpful? Give feedback.
-
+1. I have encountered the same issue. It seems that I had the same issue as @Merkie described above. I was passing a JSON Object instead of a JSON Array and that's why Prisma complained. It would have been nice to have the error handling indicate this instead of |
Beta Was this translation helpful? Give feedback.
-
Anyone else stumbling onto this. You will also get this error if you try to search for |
Beta Was this translation helpful? Give feedback.
-
I was looking for the file that throws this error message, and seems that is it: https://github.com/prisma/prisma/blob/main/packages/client/src/runtime/core/errorRendering/applyValidationError.ts This error apparently is throwing on line 306:
I think maybe this message could be changed to something like
I could do it, but I would like to discuss about this before. |
Beta Was this translation helpful? Give feedback.
-
Yeah I'm facing this currently and the error message is leading me nowhere. Running my upsert works fine in Apollo Studio (input and object types + relevant files + functions below) but are throwing this error when running e2e tests with jest. For what it's worth I'm using GraphQL and NestJS The error message is:
But if we look at the referenced line, here's what I have in async create(data: UpsertFoodJournalInput): Promise<FoodJournal> {
return await this.prismaService.foodJournal.create({ data });
} Here are the relevant files: in prisma.schema model FoodJournal {
id String @id @default(dbgenerated("(uuid())")) @db.Char(36)
note String? @db.Text
userId String @db.Char(36)
date DateTime @db.DateTime(0)
createdAt DateTime @default(now()) @db.DateTime(0)
updatedAt DateTime @default(now()) @updatedAt @db.DateTime(0)
user User @relation(name: "userFoodJournal", fields: [userId], references: [id], onDelete: Cascade)
@@index([userId], map: "userId")
@@map("food_journal")
} in types.ts @InputType()
export class UpsertFoodJournalInput {
@Field(() => ID)
@IsUUID()
userId: FoodJournal['userId'];
@Field(() => ID, { nullable: true })
@IsOptional()
@IsUUID()
id?: string;
@Field(() => String, { nullable: true })
@IsOptional()
note?: FoodJournal['note'];
@Field(() => Date, { middleware: [dateMiddleware] })
date: FoodJournal['date'];
}
@ObjectType('FoodJournal', {
description: 'FoodJournal',
})
export class FoodJournalDTO implements FoodJournal {
@Field(() => ID)
@IsUUID()
id: FoodJournal['id'];
@Field(() => ID)
@IsUUID()
userId: FoodJournal['userId'];
@Field(() => String, { nullable: true })
note: FoodJournal['note'];
@Field(() => Date, { middleware: [dateMiddleware] })
date: FoodJournal['date'];
@Field(() => Date, { middleware: [dateMiddleware] })
createdAt: Date;
@Field(() => Date, { middleware: [dateMiddleware] })
updatedAt: Date;
} in test.spec.ts describe('Domains > Food Journal', () => {
let request: E2ERequest;
let prismaService: PrismaService;
let app: INestApplication;
let userId = '';
const defaultData = {
date: new Date(),
note: 'Hellllllo',
id: null,
};
const { beforeAllHook, afterAllHook } = getE2EHooks('e2e-foodJournals');
beforeAll(async () => {
({ request, prismaService, app } = await beforeAllHook());
const user = await prismaService.user.findUniqueOrThrow({
where: { email: 'user1@user.io' },
});
userId = user.id;
});
afterAll(async () => await afterAllHook());
beforeEach(async () => {
await app.get(RedisProvider);
});
describe('Food Journal Resolver', () => {
it('should create a food journal for a given date', async () => {
const variables = {
foodJournal: {
...defaultData,
userId,
},
};
const { createdFoodJournal } = await request<
{ createdFoodJournal: FoodJournalDTO },
{ foodJournal: UpsertFoodJournalInput }
>({
document: gql`
mutation UpsertFoodJournal($foodJournal: UpsertFoodJournalInput!) {
upsertFoodJournal(foodJournal: $foodJournal) {
id
userId
note
date
createdAt
updatedAt
}
}
`;`,
variables,
});
expect(createdFoodJournal).not.toBeUndefined();
});
});
}); |
Beta Was this translation helpful? Give feedback.
-
I'm encountering a PrismaClientValidationError when trying to update a record using the Prisma ORM. The error specifically states that the argument 'companies' is missing in the 'prisma.documents_counter.update()' invocation. Here's the error message I receive:
Here are some details and code snippets related to my setup:
Here's an example code snippet that illustrates the structure of my update operation:
I have reviewed the Prisma schema, and the 'companies' field is correctly defined in the 'documents_counter' model. However, when I try to include the 'companies' field in the update operation, I receive the 'Argument 'companies' is missing' error.
Here's some part of the prisma schema:
Beta Was this translation helpful? Give feedback.
All reactions