Open dickfickling opened 2 years ago
Please show me the equivalent of Prisma Client query that you would want to execute by GraphQL API.
Here's a specific example:
model Company {
id String @id @default(cuid()) @db.Text()
name String @db.Citext()
/// @TypeGraphQL.omit(input: ["create"])
employees Employee[]
}
model Employee {
id String @id @default(cuid()) @db.Text()
name String @db.Citext()
companyId String
company Company @relation(references: [id], fields: [companyId])
}
If I run prisma generate
with that schema, the output includes an EmployeeCreateInput
class like this:
export declare class EmployeeCreateInput {
id?: string | undefined;
name: string;
company: CompanyCreateNestedOneWithoutEmployeesInput;
}
Looking at CompanyCreateNestedOneWithoutEmployeesInput
, I see:
export declare class CompanyCreateNestedOneWithoutEmployeesInput {
create?: CompanyCreateWithoutEmployeesInput | undefined;
connectOrCreate?: CompanyCreateOrConnectWithoutEmployeesInput | undefined;
connect?: CompanyWhereUniqueInput | undefined;
}
My request: I'd like to be able to specify a limitation in the schema file such that CompanyCreateNestedOneWithoutEmployeesInput
only allows connect
, and not connectOrCreate
or create
. e.g.
export declare class CompanyCreateNestedOneWithoutEmployeesInput {
connect: CompanyWhereUniqueInput;
}
Not sure what syntax would make sense for that, maybe something like
/// @TypeGraphQL.restrict(create: ["connect"])
company Company @relation(references: [id], fields: [companyId])
Does this make sense?
Ah, so you want to limit the capabilities? Sound like an interesting use case, will investigate 👀
I find myself wishing for this feature pretty regularly. @MichalLytek if I wanted to implement it myself, can you give me a very rough overview of how you'd suggest i do so?
@dickfickling A rough overview of my workflow is to: 1) Find a good DX of API for marking relation input to only create (naming is hard, you know 😅) 2) Inspect DMMF to find where the "decorator" is attached. 3) Parse the documentation from DMMF into property of that type (in transform step) - might require more complex step of transferring info from model field into input type, which is hard. 4) Adjust the inputs generator to conditionally emit the fields. 5) Write tests that checks if the new behavior works correctly.
Let's say I have two models - employee and company. Company has many employees.
I'd like to restrict the emitted types for the EmployeeCreateOneInput to only allow
connect
ing a company, notcreate
ing one. I wouldn't be surprised if this feature already exists or has already been requested. I tried to search for it and couldn't find anything.