typegraphql-prisma icon indicating copy to clipboard operation
typegraphql-prisma copied to clipboard

Graphql schema generation fails when using @TypeGraphQL.omit() on Int field

Open luca-rath opened this issue 3 years ago • 5 comments

Describe the Bug

If a prisma model contains only one single Int field which is omitted using /// @TypeGraphQL.omit(output: true, input: true), the following error occurs when generating the graphql schema:

> @ start /Users/luca/Projects/libraries/typegraphql-prisma/examples/4-nest-js
> ts-node --transpile-only ./index.ts

[Nest] 66831  - 07.02.2022, 23:17:42     LOG [NestFactory] Starting Nest application...
[Nest] 66831  - 07.02.2022, 23:17:42     LOG [InstanceLoader] AppModule dependencies initialized +39ms
[Nest] 66831  - 07.02.2022, 23:17:42   ERROR [ExceptionHandler] Some errors occurred while generating GraphQL schema:
  Input Object type PostAvgOrderByAggregateInput must define one or more fields.
,  Input Object type PostSumOrderByAggregateInput must define one or more fields.
Please check the `details` property of the error to get more detailed info.
Error: Some errors occurred while generating GraphQL schema:
  Input Object type PostAvgOrderByAggregateInput must define one or more fields.
,  Input Object type PostSumOrderByAggregateInput must define one or more fields.
Please check the `details` property of the error to get more detailed info.
    at Function.generateFromMetadata (/Users/luca/Projects/libraries/typegraphql-prisma/examples/4-nest-js/node_modules/type-graphql/dist/schema/schema-generator.js:20:23)
    at async Object.buildSchema (/Users/luca/Projects/libraries/typegraphql-prisma/examples/4-nest-js/node_modules/type-graphql/dist/utils/buildSchema.js:10:20)

To Reproduce

I have created a pull request in my fork of this repository to reproduce the bug, see https://github.com/luca-rath/typegraphql-prisma/pull/1

Expected Behavior

There should be no error

Environment (please complete the following information):

  • OS: macOS Monterey 12.2
  • Node 14.19.0
  • typegraphql-prisma version 0.18.4
  • Prisma version 3.8.1
  • TypeScript version 4.5.5

luca-rath avatar Feb 07 '22 22:02 luca-rath

Model with no fields 🤔 Interesting...

MichalLytek avatar Feb 08 '22 07:02 MichalLytek

Sorry, I expressed myself wrong ... The model contains multiple fields with types other than Int and only one single field with type Int, which is omitted using the comment

luca-rath avatar Feb 08 '22 09:02 luca-rath

This is the schema for the Post model:

model Post {
  id        String   @default(cuid()) @id
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  published Boolean
  title     String
  content   String?
  author    User?    @relation(fields: [authorId], references: [id])
  authorId  String?
  /// @TypeGraphQL.omit(output: true, input: true)
  foo       Int      @default(1)
}

luca-rath avatar Feb 08 '22 09:02 luca-rath

This is related to #19.

I think I need to find a way to do not emit those types and related fields somehow, as Prisma fix won't apply to the case of omitting the last field.

MichalLytek avatar Feb 18 '22 11:02 MichalLytek

any update?

i reproduce this error today, the only workarround i see is change the type to other than Int

image

image

Ilwel avatar Jan 03 '24 19:01 Ilwel