MichalLytek / MichalLytek/typegraphql-prisma

Possibly Incorrect Generated Type for `disconnect` in 0.27.1

Open
#426 8 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
918
Forks
130
PR merge metrics
No merged PRs in 30d

Description

**Describe the Bug**

I recently updated the `typegraphql-prisma` dependency from 0.25.1 to 0.27.1 and the `prisma` dependency from 4.16.2 to 5.4.2. After running the generation, I noticed several type errors in the application regarding the use of `disconnect` in relation queries. The way I had been using `disconnect` was to set the property to true when I needed to set a foreign key value on a table to `null`. I checked the generated types after updating to 0.27.1 and the type of the `disconnect` property is a where input type. Before the update, the type was a scalar boolean input type. Is the type of the `disconnect` property on relations correct in the new release of `typegraphql-prisma`? The `prisma` documentation shows that setting the `disconnect` property to true is valid. If this is correct, how would I disconnect a related record if I don't have the foreign key id at the time of the query? Basically, I just need to be able to set the foreign key value to null.

**To Reproduce**

Below is a minimal example to show what I'm referring to.

`schema.prisma` (which is the same in both versions)

```text
model QuestionTemplate {
QuestionTemplateId Int @id @default(autoincrement())
IndicatorTypeId Int?
IndicatorType IndicatorType? @relation(fields: [IndicatorTypeId], references: [IndicatorTypeId], onDelete: NoAction, onUpdate: NoAction, map: "fk_QuestionTemplate_IndicatorType_IndicatorTypeId")

model IndicatorType {
IndicatorTypeId Int @id @default(autoincrement())
QuestionTemplate QuestionTemplate[]
}
```

**Generated Update Input Type for 0.25.1**

```typescript
export declare class QuestionTemplateUpdateInput {
IndicatorType?: IndicatorTypeUpdateOneWithoutQuestionTemplateNestedInput | undefined;
}

export declare class IndicatorTypeUpdateOneWithoutQuestionTemplateNestedInput {
create?: IndicatorTypeCreateWithoutQuestionTemplateInput | undefined;
connectOrCreate?: IndicatorTypeCreateOrConnectWithoutQuestionTemplateInput | undefined;
upsert?: IndicatorTypeUpsertWithoutQuestionTemplateInput | undefined;
disconnect?: boolean | undefined;
delete?: boolean | undefined;
connect?: IndicatorTypeWhereUniqueInput | undefined;
update?: IndicatorTypeUpdateWithoutQuestionTemplateInput | undefined;
}
```

**Generated Update Input Type for 0.27.1**

```typescript
export declare class QuestionTemplateUpdateInput {
IndicatorType?: IndicatorTypeUpdateOneWithoutQuestionTemplateNestedInput | undefined;
}

export declare class IndicatorTypeUpdateOneWithoutQuestionTemplateNestedInput {
create?: IndicatorTypeCreateWithoutQuestionTemplateInput | undefined;
connectOrCreate?: IndicatorTypeCreateOrConnectWithoutQuestionTemplateInput | undefined;
upsert?: IndicatorTypeUpsertWithoutQuestionTemplateInput | undefined;
disconnect?: IndicatorTypeWhereInput | undefined;
delete?: IndicatorTypeWhereInput | undefined;
connect?: IndicatorTypeWhereUniqueInput | undefined;
update?: IndicatorTypeUpdateToOneWithWhereWithoutQuestionTemplateInput | undefined;
}
```

**Expected Behavior**

I expect the generated types to be the same or at least match what Prisma is showing.

**Logs**
No applicable logs

**Environment (please complete the following information):**

- OS: MacOS 14.1.1 (23B81)
- Node 18.16.0
- `typegraphql-prisma` 0.27.1
- Prisma version 5.4.2
- TypeScript version 5.1.6

**Additional Context**
No additional context that I can think of as relevant

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the provided schema.prisma and compare the generated QuestionTemplateUpdateInput and IndicatorTypeUpdateOneWithoutQuestionTemplateNestedInput types between versions 0.25.1 and 0.27.1. Reproduce generation with the listed Prisma and typegraphql-prisma versions, then verify whether disconnect and delete accept the Prisma-documented forms and whether the generated output matches the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.