unlight / prisma-nestjs-graphql

Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module
MIT License
540 stars 79 forks source link

omitModelsCount param is not working as expected #199

Open bmajkut opened 1 year ago

bmajkut commented 1 year ago

Hi, I have such simple Prisma shema (I set omitModelsCount=true)

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["postgresqlExtensions"]
}

generator nestgraphql {
    provider = "node node_modules/prisma-nestjs-graphql"
    output = "../src/@generated"
    noTypeId = true
    omitModelsCount=true
    fields_Scalars_from = "graphql-scalars"
    graphqlScalars_BigInt_name = "GraphQLBigInt"
    graphqlScalars_BigInt_specifier = "graphql-scalars"
    fields_Scalars_input=true
    fields_Scalars_output=true
    requireSingleFieldsInWhereUniqueInput=true
    emitSingle=true
    // purgeOutput=true
    reExport=true
}

datasource db {
  provider   = "postgresql"
  url        = env("DATABASE_URL")
  extensions = [citext, pgcrypto]
}

model City {
  id BigInt @id @default(autoincrement())

  value      String    @unique()
  createdAt  DateTime  @default(now())
  updatedAt  DateTime  @updatedAt
  archivedAt DateTime?

  addresses Address[]
}

model Address {
  id BigInt @id @default(autoincrement())

  zipCode     String @default("")
  building    String @default("")
  houseNumber String @default("")

  street   Street? @relation(fields: [streetId], references: [id])
  streetId BigInt?

  city   City?   @relation(fields: [cityId], references: [id])
  cityId BigInt?

  province   Provice? @relation(fields: [provinceId], references: [id])
  provinceId BigInt?

  country   Country? @relation(fields: [countryId], references: [id])
  countryId BigInt?

  documents Document[]
  obligorFiles ObligorFile[]

  createdAt  DateTime  @default(now())
  updatedAt  DateTime  @updatedAt
  archivedAt DateTime?
}

when I use prisma-nestjs-graphql generator I am getting:

@ObjectType()
export class City {
    @Field(() => GraphQLBigInt, {nullable:false})
    id!: bigint;
    @Field(() => String, {nullable:false})
    value!: string;
    @Field(() => Date, {nullable:false})
    createdAt!: Date;
    @Field(() => Date, {nullable:false})
    updatedAt!: Date;
    @Field(() => Date, {nullable:true})
    archivedAt!: Date | null;
    @Field(() => [Address], {nullable:true})
    addresses?: Array<Address>;
    @Field(() => CityCount, {nullable:false})
    _count?: InstanceType<typeof CityCount>;
}

Why Am I still getting field _count as non-nullable in Graphql?

It is a source of multiple errors on the consumer side that the types are incompatible between each other:


The types of 'document.address.city' are incompatible between these types.
      Property '_count' is missing in type '{ __typename?: "City"; id: any; value: string; createdAt: any; updatedAt: any; archivedAt?: any; }' but required in type 'City'
``

I would appreciate any hint how to deal with that. Thank You in advance.
nextor2k commented 10 months ago

@unlight any update on that issue?

unlight commented 10 months ago

I did not check it yet

nextor2k commented 10 months ago

Updated to the latest version, and it's working fine now.