prisma-nestjs-graphql icon indicating copy to clipboard operation
prisma-nestjs-graphql copied to clipboard

Custom imports

Open apss-pohl opened this issue 3 years ago • 2 comments

Hi,

it would be nice to be able to configure custom imports. When you want to use a function for the "class-validator" right now you can`t import it automated. In this example i need to import the "createValidationError" function.

model customer {
  /// @Validator.MaxLength(3, {message: createValidationError('form_string_max', ['max'])})
  number               BigInt    @db.UnsignedBigInt
}

Will be missing

import { createValidationError } from '@m/common/utils/validation-helper';

In the generated input files.

apss-pohl avatar Dec 19 '22 15:12 apss-pohl

A workaround is to create a dummy field decorator:

model customer {
  /// @CustomValidation.dummy()
  /// @Validator.MinLength(3, { message: CustomValidation.createError('form_string_min', ['min'])})
  number               BigInt    @db.UnsignedBigInt
}

Added to generator section:

    fields_CustomValidation_from = "@m/common/utils/validation-helper"
    fields_CustomValidation_input = true
    fields_CustomValidation_output = false

Will result in the wanted import:

import * as CustomValidation from '@m/common/utils/validation-helper';

But clearly rather ugly solution

apss-pohl avatar Dec 20 '22 07:12 apss-pohl

It would be great if having some solutions for this, like triple slash to add custom imports...

dnntung avatar Mar 18 '23 17:03 dnntung

@unlight Hello, sorry to tag you here. Could we please have your input on this issue? I plan to combine the nestjs-i18n library for validation messages. Importing it after code generation defeat the whole purpose.

Thanks again for your hard work

lukadriel7 avatar Nov 29 '24 11:11 lukadriel7

Merged https://github.com/unlight/prisma-nestjs-graphql/pull/230

unlight avatar Jan 25 '25 10:01 unlight