typegraphql-prisma
typegraphql-prisma copied to clipboard
Graphql schema generation fails when using @TypeGraphQL.omit() on Int field
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
Model with no fields 🤔 Interesting...
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
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)
}
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.
any update?
i reproduce this error today, the only workarround i see is change the type to other than Int