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

Fields missing in "input" if there is a relation

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

I am missing fields if there is a relation based on those. E.g.:

model customerTest {
  id               Int       @id @default(autoincrement()) @db.UnsignedInt
  /// @Validator.IsInt()
  posId            Int       @db.UnsignedTinyInt

  posRelation     posSettings    @relation(fields: [posId], references: [id])
}

Will result in "customer-test-create.input.ts":

import { Field } from '@nestjs/graphql';
import { InputType } from '@nestjs/graphql';
import { posSettingsCreateNestedOneWithoutCustomerTestInput } from '../../pos-settings/inputs/pos-settings-create-nested-one-without-customer-test.input';
import { Type } from 'class-transformer';

@InputType()
export class customerTestCreateInput {

    @Field(() => posSettingsCreateNestedOneWithoutCustomerTestInput, {nullable:false})
    @Type(() => posSettingsCreateNestedOneWithoutCustomerTestInput)
    posRelation!: posSettingsCreateNestedOneWithoutCustomerTestInput;
}

Which makes it impossible to set the "posId" directly.

apss-pohl avatar Jan 13 '23 16:01 apss-pohl

Same type generated by prisma (without id). You can:

  1. Remove @default(autoincrement()) from customerTest
  2. Use customerTestUncheckedCreateInput instead

unlight avatar Jan 13 '23 19:01 unlight

Hi, thanks for your hint. "customerTestUncheckedCreateInput" does the job. "@default(autoincrement())" has no input on posId. I could not find anything about these "*Unchecked" args in the prisma documentation, whats the idea behind? Is there any kind of rule when to use it?

apss-pohl avatar Jan 16 '23 06:01 apss-pohl

I'm facing the same issue below is my prisma model model User { id Int @id @unique @default(autoincrement())

/// @Validator.IsEmail() email String @unique

/// @Validator.IsString() /// @Validator.MaxLength(100) /// @Validator.MinLength(3) name String? posts post[] }

model post { id Int @id @unique

/// @Validator.IsString() /// @Validator.MaxLength(1000) description String?

user User @relation(fields: [userId], references: [id]) userId Int @default(0)// relation scalar field (used in the @relation attribute above) }

And this is how my types and mutation looks input postCreateInput { id: Int! description: String user: UserCreateNestedOneWithoutPostsInput }

mutation addPost($data: postCreateInput!){ createPost(data: $data) { description userId user { name email } } } { "data": { "id": 1, "description": "testing the first input", "userId" : 1 } }

Error : "message": "Variable "$data" got invalid value { description: "testing the first input", userId: 1 }; Field "id" of required type "Int!" was not provided.",

saboorajat avatar Oct 21 '23 10:10 saboorajat

Same type generated by prisma (without id). You can:

1. Remove `@default(autoincrement())` from `customerTest`

2. Use `customerTestUncheckedCreateInput` instead

Doesn't work for me

saboorajat avatar Oct 21 '23 19:10 saboorajat