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

Weird naming for *CreateInput #226

Open
kasir-barati opened this issue Dec 3, 2024 · 1 comment
Open

Weird naming for *CreateInput #226

kasir-barati opened this issue Dec 3, 2024 · 1 comment
Labels
awaiting-feedback invalid This doesn't seem right question Further information is requested

Comments

@kasir-barati
Copy link

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.

@unlight
Copy link
Owner

unlight commented Jan 26, 2025

why we have AlertType

You have AlertType field in your schema, if you will check prisma types you will see the same field in AlertCreateMany type

@unlight unlight added awaiting-feedback invalid This doesn't seem right question Further information is requested labels Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-feedback invalid This doesn't seem right question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants