nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.45k stars 392 forks source link

TypeError: Cannot read property 'properties' of undefined #1042

Closed JasonJie closed 4 years ago

JasonJie commented 4 years ago

$ nest start [Nest] 18065 - 2020-07-17 4:38:05 ├F10: PM┤ [NestFactory] Starting Nest application... [Nest] 18065 - 2020-07-17 4:38:05 ├F10: PM┤ [InstanceLoader] PostsModule dependencies initialized +26ms [Nest] 18065 - 2020-07-17 4:38:05 ├F10: PM┤ [InstanceLoader] AppModule dependencies initialized +1ms [Nest] 18065 - 2020-07-17 4:38:05 ├F10: PM┤ [InstanceLoader] AuthorsModule dependencies initialized +0ms [Nest] 18065 - 2020-07-17 4:38:05 ├F10: PM┤ [InstanceLoader] GraphQLSchemaBuilderModule dependencies initialized +1ms [Nest] 18065 - 2020-07-17 4:38:05 ├F10: PM┤ [InstanceLoader] GraphQLModule dependencies initialized +1ms [Nest] 18065 - 2020-07-17 4:38:05 ├F10: PM┤ [RoutesResolver] AppController {}: +5ms [Nest] 18065 - 2020-07-17 4:38:05 ├F10: PM┤ [RouterExplorer] Mapped {, GET} route +3ms (node:18065) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'properties' of undefined at TypeMetadataStorageHost.compileExternalFieldResolverMetadata (/Users/junjie/Jie/nestjs/demo/node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:249:74) at /Users/junjie/Jie/nestjs/demo/node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:239:22 at Array.forEach () at TypeMetadataStorageHost.compileFieldResolverMetadata (/Users/junjie/Jie/nestjs/demo/node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:228:18) at TypeMetadataStorageHost.compile (/Users/junjie/Jie/nestjs/demo/node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:143:14) at GraphQLSchemaFactory. (/Users/junjie/Jie/nestjs/demo/node_modules/@nestjs/graphql/dist/schema-builder/graphql-schema.factory.js:39:61) at Generator.next () at /Users/junjie/Jie/nestjs/demo/node_modules/tslib/tslib.js:114:75 at new Promise () at Object.__awaiter (/Users/junjie/Jie/nestjs/demo/node_modules/tslib/tslib.js:110:16) (node:18065) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:18065) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ✨ Done in 13.90s.

image

kamilmysliwiec commented 4 years ago

Please provide a minimum reproduction repository.

JasonJie commented 4 years ago

"dependencies": { "@nestjs/common": "^7.1.1", "@nestjs/core": "^7.1.1", "@nestjs/graphql": "^7.5.5", "@nestjs/platform-express": "^7.1.1", "apollo-server-express": "^2.15.1", "class-validator": "^0.12.2", "graphql": "^15.3.0", "graphql-tools": "^6.0.12", "lodash": "^4.17.19", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^6.5.5", "type-graphql": "^1.0.0-rc.3" }, "devDependencies": { "@nestjs/cli": "^7.2.0", "@nestjs/schematics": "^7.0.0", "@nestjs/testing": "^7.1.1", "@types/express": "^4.17.6", "@types/jest": "^25.2.3", "@types/node": "^14.0.6", "@types/supertest": "^2.0.9", "@typescript-eslint/eslint-plugin": "^3.0.2", "@typescript-eslint/parser": "^3.0.2", "eslint": "^7.1.0", "eslint-config-prettier": "^6.11.0", "eslint-plugin-import": "^2.20.2", "jest": "^26.0.1", "prettier": "^2.0.5", "supertest": "^4.0.2", "ts-jest": "^26.1.0", "ts-loader": "^7.0.5", "ts-node": "^8.10.2", "tsconfig-paths": "^3.9.0", "typescript": "^3.9.3" },

@kamilmysliwiec

JasonJie commented 4 years ago

@kamilmysliwiec how can i fix this

kamilmysliwiec commented 4 years ago

We can't help without a minimum reproduction Github repository.

WhatzzUp commented 4 years ago

Hey, mate @JasonJie, I guess you updated your nestjs version from 6 to 7?

A few minutes ago I stepped into the same error and fixed it by reading @kamilmysliwiec migration guide at https://docs.nestjs.com/migration-guide#graphql

image

Following migration advice fixed my issue 🥳 :

In order to migrate your existing application, simply rename all the type-graphql imports to the @nestjs/graphql

May it helps, cheers

nilscox commented 4 years ago

Hi @kamilmysliwiec, I also have this error. Here is a repro repository: https://github.com/nilscox/repro-nestjs-graphql-field-resolver.

Just yarn and yarn start, and you should see the same error described above:

[Nest] 126369   - 07/27/2020, 4:49:08 PM   [NestFactory] Starting Nest application...
[Nest] 126369   - 07/27/2020, 4:49:08 PM   [InstanceLoader] AppModule dependencies initialized +12ms
[Nest] 126369   - 07/27/2020, 4:49:08 PM   [InstanceLoader] GraphQLSchemaBuilderModule dependencies initialized +1ms
[Nest] 126369   - 07/27/2020, 4:49:08 PM   [InstanceLoader] GraphQLModule dependencies initialized +0ms
(node:126369) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'properties' of undefined
    at TypeMetadataStorageHost.compileExternalFieldResolverMetadata (/tmp/test-graphql/node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:249:74)
    at /tmp/test-graphql/node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:239:22
    at Array.forEach (<anonymous>)
    at TypeMetadataStorageHost.compileFieldResolverMetadata (/tmp/test-graphql/node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:228:18)
    at TypeMetadataStorageHost.compile (/tmp/test-graphql/node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:143:14)
    at GraphQLSchemaFactory.<anonymous> (/tmp/test-graphql/node_modules/@nestjs/graphql/dist/schema-builder/graphql-schema.factory.js:39:61)
    at Generator.next (<anonymous>)
    at /tmp/test-graphql/node_modules/tslib/tslib.js:114:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/tmp/test-graphql/node_modules/tslib/tslib.js:110:16)

Edit: Replacing "target": "es5" with "target": "es2017" in the tsconfig.json fixed the problem.

tumainimosha commented 4 years ago

Hi @nilscox did you get a solution to this. Facing similar issue

nilscox commented 4 years ago

I updated typescript's target to es2017. This fixed the problem for me. https://github.com/nilscox/repro-nestjs-graphql-field-resolver/compare/fixed

piyushwork commented 1 year ago

Hi @nilscox got the same issue and did what you suggested but it did not worked for me any other workaround or something else you would like to suggest ??

nilscox commented 10 months ago

Hello, I'm sorry it was a while ago, I don't have other tips for you.