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

Create one record with foreign key

Open ghost opened this issue 2 years ago • 0 comments
trafficstars

This look weird to me,

export class MovieCreateInput {
    @Field(() => String, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsString()
    title!: string;

    @Field(() => Float, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsNumber()
    timing!: number;

    @Field(() => String, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsString()
    desc!: string;

    @Field(() => String, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsString()
    director!: string;

    @Field(() => String, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsString()
    members!: string;

    @Field(() => Date, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsDate()
    openingDay!: Date | string;

    @Field(() => String, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsString()
    poster!: string;

    @Field(() => String, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsString()
    trailer!: string;

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

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

    @Field(() => CategoryCreateNestedOneWithoutMoviesInput, {nullable:false})
    category!: CategoryCreateNestedOneWithoutMoviesInput;

    @Field(() => BadgeCreateNestedOneWithoutMoviesInput, {nullable:false})
    badge!: BadgeCreateNestedOneWithoutMoviesInput;

    @Field(() => ShowTimeCreateNestedManyWithoutMovieInput, {nullable:true})
    showTimes?: ShowTimeCreateNestedManyWithoutMovieInput;
}

and

import { Field } from '@nestjs/graphql';
import { InputType } from '@nestjs/graphql';
import { Int } from '@nestjs/graphql';
import * as Validator from 'class-validator';
import { Float } from '@nestjs/graphql';

@InputType()
export class MovieCreateManyInput {

    @Field(() => Int, {nullable:true})
    id?: number;

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

    @Field(() => Float, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsNumber()
    timing!: number;

    @Field(() => String, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsString()
    desc!: string;

    @Field(() => String, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsString()
    director!: string;

    @Field(() => String, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsString()
    members!: string;

    @Field(() => Date, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsDate()
    openingDay!: Date | string;

    @Field(() => Int, {nullable:false})
    categoryId!: number;

    @Field(() => Int, {nullable:false})
    badgeId!: number;

    @Field(() => String, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsString()
    poster!: string;

    @Field(() => String, {nullable:false})
    @Validator.IsNotEmpty()
    @Validator.IsString()
    trailer!: string;

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

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

When I want to create one movie, why I need provide category and badge object instead of just categoryId and badgeId.

  • It's not good to me. Also in @generated I got the MovieCreateManyInput. It's better than MovieCreateInput. This is bug or feature? Can guys explain to me why we have this difference?

ghost avatar Nov 10 '23 12:11 ghost