MichalLytek / type-graphql

Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
https://typegraphql.com
MIT License
7.99k stars 674 forks source link

Issue with unnamed @InputType() #1550

Closed vanduc1102 closed 9 months ago

vanduc1102 commented 9 months ago

Describe the Bug I am using typed-graphql in a nextjs13 project , the project work well in development mode, but production mode cannot work correctly,

Here are some logs :

Schema must contain uniquely named types but contains multiple types named "d". /Users/duc.nguyen/Workspace/github/sample-project/node_modules/graphql/type/schema.js [I jump into the file to print the line ]
ERR TypeError: Cannot read properties of undefined (reading 'http')
    at file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/graphql-yoga/esm/plugins/request-validation/use-http-validation-error.js:8:49
    at Object.validate (file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/@envelop/core/esm/orchestrator.js:174:17)
    at processRequest (file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/graphql-yoga/esm/process-request.js:37:30)
    at YogaServer.getResultForParams (file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/graphql-yoga/esm/server.js:300:32)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at YogaServer.handle (file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/graphql-yoga/esm/server.js:73:29)
    at handlerWithErrorHandling (file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/@whatwg-node/server/esm/plugins/useErrorHandling.js:28:38)
ERR TypeError: Cannot read properties of undefined (reading 'http')
    at file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/graphql-yoga/esm/plugins/request-validation/use-http-validation-error.js:8:49
    at Object.validate (file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/@envelop/core/esm/orchestrator.js:174:17)
    at processRequest (file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/graphql-yoga/esm/process-request.js:37:30)
    at YogaServer.getResultForParams (file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/graphql-yoga/esm/server.js:300:32)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at YogaServer.handle (file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/graphql-yoga/esm/server.js:73:29)
    at handlerWithErrorHandling (file:///Users/duc.nguyen/Workspace/github/sample-project/node_modules/@whatwg-node/server/esm/plugins/useErrorHandling.js:28:38)

Looks like to me that a random name with 1 character is generated for InputType without name,

To Reproduce

I have an example here, https://github.com/vanduc1102/nextjs13-prisma-typedgraphql/pull/1/files

the sample work well in dev mode,

but in production mode, you will receive error when click on button Click me to test mutation

The error is different , but it can be fix if I give a name for CustomizedType3Input @InputType("CustomizedType3Input")

Expected Behavior

Is there a way to have warning , or set the name of InputType mandatory.

Logs If applicable, add some console logs to help explain your problem. You can paste the errors with stack trace that were printed when the error occurred.

Environment (please complete the following information):

Additional Context Add any other context about the problem here.

MichalLytek commented 9 months ago

Disable minification, especially class name related.

vanduc1102 commented 9 months ago

Hi @MichalLytek , thank you for replying,

Do you mean that, the issue is because I am using NextJS, when the build happens, it will minify name of classes ?

Do you have any guides or documents for doing that with NextJS@13 ?

Thanks.