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

Create one record with foreign key #198

Open
ghost opened this issue Nov 10, 2023 · 0 comments
Open

Create one record with foreign key #198

ghost opened this issue Nov 10, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented Nov 10, 2023

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?
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

0 participants