MichalLytek / typegraphql-prisma

Prisma generator to emit TypeGraphQL types and CRUD resolvers from your Prisma schema
https://prisma.typegraphql.com
MIT License
887 stars 113 forks source link

Issue with generating the resolvers in outputs #454

Open dharmendraboddeda opened 4 months ago

dharmendraboddeda commented 4 months ago

Incorectly generating the rosolvers i have used this same prisma schema at typegraphql-prisma version (0.27.1) but now when use current version 0.27.2 , i am facing the issue generating the resolvers.

generator typegraphql {
  provider           = "typegraphql-prisma"
  output             = "../generated/type-graphql"
  emitTranspiledCode = false
}

To Reproduce 2024-06-06-171042_screenshot

its generating this path

api/generated/type-graphql/resolvers/outputs/CreateManyChatsAndReturnOutputType.ts

and in this return outputType files this kind of modules are not resolving

import { Folder } from "../outputs/Folder";

but previous version that i have used i didn't get generate this files please resolve my issue

Expected Behavior 2024-06-06-171118_screenshot

See i have used typegraphql-prisma: "0.27.1"

Logs

    at _buildSchemaBin (file:///home/dharmendraboddeda/Projects/promanager/conversation-explorer-new/node_modules/@multiplatform.one/typegraphql/lib/chunk-SNLZTJW7.mjs:22:41) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///home/dharmendraboddeda/Projects/promanager/conversation-explorer-new/api/dist/api/main.mjs'
}

Node.js v20.12.1
node:internal/modules/cjs/loader:1146
  throw err;
  ^

Error: Cannot find module '/home/dharmendraboddeda/Projects/promanager/conversation-explorer-new/api/dist/api/main.mjs'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v20.12.1
Could not resolve "../outputs/Folder" from "generated/type-graphql/resolvers/outputs/CreateManyChatsAndReturnOutputType.ts"
file: /home/dharmendraboddeda/Projects/promanager/conversation-explorer-new/api/generated/type-graphql/resolvers/outputs/CreateManyChatsAndReturnOutputType.ts

Environment (please complete the following information):

MichalLytek commented 4 months ago

Duplicate of #450?

Romanchuk commented 3 months ago

I have the same issue

savager commented 3 months ago

CreateMany files are improperly importing the models it seems:

image

Maybe should be:

image

vnamana commented 3 months ago

image I faced same issue and above change solves the issue, at least runtime error is not showing up after this fix.. this needs to be fixed in code where these imports are autogenerated at package level so that when running 'npm install' generates files with this fix when using below code in schema.prisma file:

generator typegraphql {
  provider           = "typegraphql-prisma"
}
RubenNL commented 3 months ago

With the findings of the earlier comments, I added this after my prisma generate step:

find path-of-typegraphql-output/resolvers/outputs -type f -name 'CreateMany*' -exec sed -i 's/\.\.\/outputs\//\.\.\/\.\.\/models\//g' {} \;

Replace path-of-typegraphql-output with the default ./node_modules/@generated/type-graphql, or the output option configured in your prisma schema.

This does the same as what @savager found here: https://github.com/MichalLytek/typegraphql-prisma/issues/454#issuecomment-2159845608

All of my old queries are working, but as I have a read-only database, I can't test the createMany.

the-simian commented 3 months ago

Adding this to the package.json seems to be a temporary workaround

  "overrides": {
    "@prisma/generator-helper": "^5.4.2 <=5.13.0",
    "@prisma/internals": "^5.4.2 <=5.13.0"
  }