Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use prisma generated type for model argument #456

Open
darr1s opened this issue Apr 4, 2023 · 1 comment
Open

Use prisma generated type for model argument #456

darr1s opened this issue Apr 4, 2023 · 1 comment

Comments

@darr1s
Copy link

darr1s commented Apr 4, 2023

Description

Hello again, I am suggesting that we use the interface exported by @prisma/client on built to pass into model: during constructor.

Motivation and Context

  1. Better type-safety
  2. Potentially allowing Swagger doc to show possible field

Examples

Instead of

@Injectable()
export class WebhookService extends PrismaCrudService {
  constructor() {
    super({
      model: 'webhook',
      allowedJoins: ['tenant', 'file'],
      defaultJoins: [],
    })
  }
}

We do

import { Webhook } from '@prisma/client'

@Injectable()
export class WebhookService extends PrismaCrudService {
  constructor() {
    super({
      model: Webhook,
      allowedJoins: ['tenant', 'file'], // e.g. Error will be thrown when a wrong field is passed in
      defaultJoins: [],
    })
  }
}

Reference

I've seen this being done in https://github.com/chax-at/prisma-filter that its @DirectFilterPipe will recognize the field types in the whitelist array.

@kepelrs
Copy link
Owner

kepelrs commented Apr 9, 2023

One thing I'm wondering is allowedJoins accepts dot notated deep joins (eg. allowedJoins: ['tenant.users.comments', 'file']). Would be nice if that could be type safe as well.

Not sure when I'll have bandwidth for this, but I like the direction. PR's are also welcome if you feel like it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants