MichalLytek / typegraphql-prisma

Prisma generator to emit TypeGraphQL types and CRUD resolvers from your Prisma schema

Home Page:https://prisma.typegraphql.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Syntax error in a particular generated RelationsResolver

altintx opened this issue · comments

Describe the Bug
I have a prisma model called Case. It is a core concept in this application and an unfortunate keyword collision in the TS world. When the RelationsResolver for it is generated, the file is syntactically invalid, and subsequent POSTs to /api/graphql fail with what's advertised as a webpack PackFileCacheStrategy Error but is in fact a syntax error in the generated file.

Module parse failed: Unexpected token (98:1)
// ...

where lines 97/98 are

 | ], CaseRelationsResolver);
 >  | null > {

Everything past that point is independently full of errors like

const: { _count } = (0, helpers_1.transformInfoIntoPrismaArgs)(info),
    return: (0, helpers_1.getPrismaFromContext)(ctx).case.findUniqueOrThrow({
        where: {
            id: , case: .id,
        },
    }).requestedBy({
        ...args,
        ...(_count && (0, helpers_1.transformCountFieldIntoSelectRelationsCount)(_count)),
    })

Notice the missing variables in the where condition id: , case: .id

If I delete all references to CaseRelationsResolver in generated code, other types work as expected. I haven't found a way to prevent it from being generated in the first place.

To Reproduce
1: schema.prisma:

model Case { 
  id String @id @default(cuid())
  name String
  surgeonId String? 
  surgeon Surgeon? @relation(fields: [surgeonId], references: [id])

}
model Surgeon {
  id String @id @default(cuid())
  name String 
  cases Case[]
}

2: $ prisma generate

Expected Behavior
For this model's RelationsResolver to be syntactically valid and comparable to other RelationsResolvers

Logs

scheduling:dev: <w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (101kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
scheduling:dev:  ⨯ ../../packages/database/node_modules/@generated/type-graphql/resolvers/relations/Case/CaseRelationsResolver.js
scheduling:dev: Module parse failed: Unexpected token (98:1)
scheduling:dev: You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
scheduling:dev: |     TypeGraphQL.Resolver(_of => Case_1.Case)
scheduling:dev: | ], CaseRelationsResolver);
scheduling:dev: >  | null > {
scheduling:dev: |     const: { _count } = (0, helpers_1.transformInfoIntoPrismaArgs)(info),
scheduling:dev: |     return: (0, helpers_1.getPrismaFromContext)(ctx).case.findUniqueOrThrow({
scheduling:dev: 
scheduling:dev: Import trace for requested module:
scheduling:dev: ../../packages/database/node_modules/@generated/type-graphql/resolvers/relations/Case/CaseRelationsResolver.js
scheduling:dev: ../../packages/database/node_modules/@generated/type-graphql/resolvers/relations/resolvers.index.js
scheduling:dev: ../../packages/database/node_modules/@generated/type-graphql/index.js
scheduling:dev: ./src/pages/api/graphql.ts
scheduling:dev:  ⨯ ../../packages/database/node_modules/@generated/type-graphql/resolvers/relations/Case/CaseRelationsResolver.js

Environment (please complete the following information):

  • OS: MacOS 13.2.1
  • Node: 20.10.0
  • typegraphql-prisma version 0.27.1
  • Prisma version 5.9.1
  • TypeScript version 4.3.3 5.3.3

Additional Context
Add any other context about the problem here.

Please rename your model to something not being a keyword:
https://prisma.typegraphql.com/docs/advanced/renaming-model