MichalLytek / MichalLytek/typegraphql-prisma
Allow configuring nullability
- Dominant language
- TypeScript
- Stars
- 918
- Forks
- 130
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
Take the following schema
```prisma
model User {
id Int @id @default(autoincrement())
email String
firstName String
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
message String
author User @relation(fields: [authorId], references: [id])
authorId Int
}
```
I'd like to create a middleware or decorator that automatically connects `currentUser` (from context) to the `author` field of `Post` in the `CreatePostResolver`. For example
```typescript
export const ConnectCurrentUser: MiddlewareFn = async ({ context }, next) => {
if (!context.currentUser) {
throw new ValidationError()
}
return {
connect: {
id: context.currentUser.id,
} as UserWhereUniqueInput,
}
}
applyInputTypesEnhanceMap({
PostCreateInput: {
fields: {
author: [UseMiddleware(ConnectCurrentUser)],
},
},
})
```
This would work fine, however `nullable: false` on the `author` field prevents the mutation from working without any input for the field.
**Describe the solution you'd like**
I'd love a way to configure nullability on a per-field basis.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start from the applyInputTypesEnhanceMap entry point and the PostCreateInput.author example, then trace how nullability is generated for the CreatePostResolver input. Done means a per-field nullability configuration exists and the shown middleware-based mutation can omit author input while connecting the current user.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100