Skip to content

Weird naming for *CreateInput #226

@kasir-barati

Description

@kasir-barati

Here is my schema.prisma:

generator client {
  provider = "prisma-client-js"
}

generator nestgraphql {
  provider = "node node_modules/prisma-nestjs-graphql"
  output   = "../src/@generated"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model AlertType {
  id          String    @id @default(uuid())
  name        String    @unique @db.VarChar(200)
  description String?   @db.VarChar(500)
  createdAt   DateTime  @default(now()) @map("created_at") @db.Timestamptz()
  updatedAt   DateTime? @updatedAt @map("updated_at") @db.Timestamptz()

  Alerts Alert[]

  @@map("alert_types")
}

model Alert {
  id          String    @id @default(uuid())
  title       String    @db.VarChar(200)
  description String?   @db.VarChar(500)
  userId      String    @map("user_id") @db.Uuid
  createdAt   DateTime  @default(now()) @map("created_at") @db.Timestamptz()
  updatedAt   DateTime? @updatedAt @map("updated_at") @db.Timestamptz()

  AlertType   AlertType @relation(fields: [alertTypeId], references: [id])
  alertTypeId String    @map("alert_type_id")

  @@map("alerts")
}

Why when I run the prisma generate my AlertCreateInput looks like this:

import { Field } from '@nestjs/graphql';
import { InputType } from '@nestjs/graphql';
import { AlertTypeCreateNestedOneWithoutAlertsInput } from '../alert-type/alert-type-create-nested-one-without-alerts.input';

@InputType()
export class AlertCreateInput {

    @Field(() => String, {nullable:true})
    id?: string;

    @Field(() => String, {nullable:false})
    title!: string;

    @Field(() => String, {nullable:true})
    description?: string;

    @Field(() => String, {nullable:false})
    userId!: string;

    @Field(() => Date, {nullable:true})
    createdAt?: Date | string;

    @Field(() => Date, {nullable:true})
    updatedAt?: Date | string;

    @Field(() => AlertTypeCreateNestedOneWithoutAlertsInput, {nullable:false})
    AlertType!: AlertTypeCreateNestedOneWithoutAlertsInput;
}

This does not make any sense to me, why we have AlertType while I was expecting it to have alertTypeId instead. And instead the AlertCreateManyInput kinda makes more sense but the naming this time is not correct IMO:

import { Field } from '@nestjs/graphql';
import { InputType } from '@nestjs/graphql';

@InputType()
export class AlertCreateManyInput {

    @Field(() => String, {nullable:true})
    id?: string;

    @Field(() => String, {nullable:false})
    title!: string;

    @Field(() => String, {nullable:true})
    description?: string;

    @Field(() => String, {nullable:false})
    userId!: string;

    @Field(() => Date, {nullable:true})
    createdAt?: Date | string;

    @Field(() => Date, {nullable:true})
    updatedAt?: Date | string;

    @Field(() => String, {nullable:false})
    alertTypeId!: string;
}

I also saw issue #219 which also has the same issue since we have AlertCreateManyAlertTypeInput which does not have any of relation fields but its name is really confusing.

I would love to see/contribute on making this naming better. @unlight how can I make this change. I am not sure from where I should start TBH. And I also fear this might introduce breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions