nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.9k stars 7.55k forks source link

Prisma example code needs explicit types specified for PostsResolver #2187

Closed peterbabic closed 5 years ago

peterbabic commented 5 years ago

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

/mnt/d/dev/_learn/nest/repo/sample/22-graphql-prisma/node_modules/type-graphql/dist/helpers/findType.js:17
        throw new errors_1.NoExplicitTypeError(prototype.constructor.name, propertyKey, parameterIndex);
              ^
Error: You need to provide explicit type for PostsResolver#getPosts parameter #0 !
    at Object.findType (/mnt/d/dev/_learn/nest/repo/sample/22-graphql-prisma/node_modules/type-graphql/dist/helpers/findType.js:17:15)
    at Object.getParamInfo (/mnt/d/dev/_learn/nest/repo/sample/22-graphql-prisma/node_modules/type-graphql/dist/helpers/params.js:9:49)
    at Args (/mnt/d/dev/_learn/nest/repo/sample/22-graphql-prisma/node_modules/type-graphql/dist/decorators/Args.js:9:120)
    at Args (/mnt/d/dev/_learn/nest/repo/sample/22-graphql-prisma/node_modules/@nestjs/graphql/dist/decorators/args.decorator.js:27:49)
    at /mnt/d/dev/_learn/nest/repo/sample/22-graphql-prisma/src/posts/posts.resolver.ts:12:37
    at DecorateProperty (/mnt/d/dev/_learn/nest/repo/sample/22-graphql-prisma/node_modules/reflect-metadata/Reflect.js:553:33)
    at Object.decorate (/mnt/d/dev/_learn/nest/repo/sample/22-graphql-prisma/node_modules/reflect-metadata/Reflect.js:123:24)
    at __decorate (/mnt/d/dev/_learn/nest/repo/sample/22-graphql-prisma/src/posts/posts.resolver.ts:4:92)
    at Object.<anonymous> (/mnt/d/dev/_learn/nest/repo/sample/22-graphql-prisma/src/posts/posts.resolver.ts:20:3)
    at Module._compile (module.js:653:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nest-typescript-starter@1.0.0 start: `ts-node src/main`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nest-typescript-starter@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/delmadord/.npm/_logs/2019-05-13T22_59_07_077Z-debug.log

Expected behavior

Working Nest + Prisma example

Minimal reproduction of the problem with instructions

git clone https://github.com/nestjs/nest.git
cd nest/sample/22-graphql-prisma
npm install
# npm WARN @nestjs/graphql@6.0.5 requires a peer of type-graphql@^0.17.0 but none is installed. You must install peer dependencies yourself.
npm install --save type-graphql@^0.17.0
npm run build
npm run start

What is the motivation / use case for changing the behavior?

The sample code does not run on my machine. Related: https://github.com/19majkel94/type-graphql/issues/135

Environment

Bothe environments output the same error, master on 0137ebce0034eada279abae64231789bd11dfbe1

kamilmysliwiec commented 5 years ago

Update @nestjs/graphql to the latest version

peterbabic commented 5 years ago

Thank You for the reply but unfortunately:

git clone https://github.com/nestjs/nest.git
cd nest/sample/22-graphql-prisma
npm install
npm run start

produces

[Nest] 564   - 2019-05-16 10:53   [NestFactory] Starting Nest application...
[Nest] 564   - 2019-05-16 10:53   [InstanceLoader] ApplicationModule dependencies initialized +180ms
[Nest] 564   - 2019-05-16 10:53   [InstanceLoader] PrismaModule dependencies initialized +3ms
[Nest] 564   - 2019-05-16 10:53   [InstanceLoader] PostsModule dependencies initialized +3ms
[Nest] 564   - 2019-05-16 10:53   [InstanceLoader] GraphQLModule dependencies initialized +3ms
(node:564) UnhandledPromiseRejectionWarning: Error: Unknown directive "unique".

Unknown directive "default".
    at assertValidSDL (/mnt/d/dev/_learn/nest/nest/sample/22-graphql-prisma/node_modules/graphql/validation/validate.js:89:11)
    at Object.buildASTSchema (/mnt/d/dev/_learn/nest/nest/sample/22-graphql-prisma/node_modules/graphql/utilities/buildASTSchema.js:78:34)
    at Object.buildSchemaFromTypeDefinitions (/mnt/d/dev/_learn/nest/nest/sample/22-graphql-prisma/node_modules/graphql-tools/src/generate/buildSchemaFromTypeDefinitions.ts:43:32)
    at Object.makeExecutableSchema (/mnt/d/dev/_learn/nest/nest/sample/22-graphql-prisma/node_modules/graphql-tools/src/makeExecutableSchema.ts:52:16)
    at GraphQLFactory.<anonymous> (/mnt/d/dev/_learn/nest/nest/sample/22-graphql-prisma/node_modules/@nestjs/graphql/dist/graphql.factory.js:68:62)
    at Generator.next (<anonymous>)
    at /mnt/d/dev/_learn/nest/nest/sample/22-graphql-prisma/node_modules/@nestjs/graphql/dist/graphql.factory.js:16:71
    at new Promise (<anonymous>)
    at __awaiter (/mnt/d/dev/_learn/nest/nest/sample/22-graphql-prisma/node_modules/@nestjs/graphql/dist/graphql.factory.js:12:12)
    at GraphQLFactory.mergeOptions (/mnt/d/dev/_learn/nest/nest/sample/22-graphql-prisma/node_modules/@nestjs/graphql/dist/graphql.factory.js:41:16)
(node:564) 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(). (rejection id: 3)
(node:564) [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.

No mention about type-graphql package though.

brainsbucket commented 5 years ago

+1 exactly the same for me

kamilmysliwiec commented 5 years ago

Update your packages to the latest @nestjs/graphql

brainsbucket commented 5 years ago

thansk for the reply. the @nestjs/graphql package is at version 6.2.4

this is my package.json :

{
  "name": "nest-typescript-starter",
  "version": "1.0.0",
  "description": "Nest TypeScript starter repository",
  "license": "MIT",
  "scripts": {
    "build": "tsc -p tsconfig.build.json",
    "start": "ts-node src/main",
    "prestart:prod": "npm run build",
    "start:prod": "node dist/main.js"
  },
  "dependencies": {
    "@nestjs/common": "6.3.1",
    "@nestjs/core": "6.3.1",
    "@nestjs/graphql": "6.2.4",
    "@nestjs/platform-express": "6.3.1",
    "apollo-server-express": "2.6.1",
    "graphql": "14.3.1",
    "graphql-tools": "4.0.4",
    "prisma-binding": "2.3.11",
    "reflect-metadata": "0.1.13",
    "rxjs": "6.5.2",
    "typescript": "3.5.1"
  },
  "devDependencies": {
    "nodemon": "1.19.1",
    "prettier": "1.17.1",
    "ts-node": "8.2.0",
    "tsconfig-paths": "3.8.0",
    "tslint": "5.17.0"
  }
}

I have the same error than @peterbabic when I run npm run start:

[Nest] 6893   - 2019-06-06 18:17   [NestFactory] Starting Nest application...
[Nest] 6893   - 2019-06-06 18:17   [InstanceLoader] ApplicationModule dependencies initialized +62ms
[Nest] 6893   - 2019-06-06 18:17   [InstanceLoader] PrismaModule dependencies initialized +1ms
[Nest] 6893   - 2019-06-06 18:17   [InstanceLoader] PostsModule dependencies initialized +1ms
[Nest] 6893   - 2019-06-06 18:17   [InstanceLoader] GraphQLModule dependencies initialized +1ms
(node:6893) UnhandledPromiseRejectionWarning: Error: Unknown directive "unique".

Unknown directive "default".
    at assertValidSDL (/var/node/nest-prisma/node_modules/graphql/validation/validate.js:89:11)
    at Object.buildASTSchema (/var/node/nest-prisma/node_modules/graphql/utilities/buildASTSchema.js:78:34)
    at Object.buildSchemaFromTypeDefinitions (/var/node/nest-prisma/node_modules/graphql-tools/src/generate/buildSchemaFromTypeDefinitions.ts:43:32)
    at Object.makeExecutableSchema (/var/node/nest-prisma/node_modules/graphql-tools/src/makeExecutableSchema.ts:52:16)
    at GraphQLFactory.<anonymous> (/var/node/nest-prisma/node_modules/@nestjs/graphql/dist/graphql.factory.js:68:62)
    at Generator.next (<anonymous>)
    at /var/node/nest-prisma/node_modules/@nestjs/graphql/dist/graphql.factory.js:16:71
    at new Promise (<anonymous>)
    at __awaiter (/var/node/nest-prisma/node_modules/@nestjs/graphql/dist/graphql.factory.js:12:12)
    at GraphQLFactory.mergeOptions (/var/node/nest-prisma/node_modules/@nestjs/graphql/dist/graphql.factory.js:41:16)
(node:6893) 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(). (rejection id: 2)
(node:6893) [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.
mario-huang commented 5 years ago

update to "@nestjs/graphql": "6.4.2", still show UnhandledPromiseRejectionWarning: Error: Unknown directive "unique".

sangdth commented 5 years ago

I got a similar problem when I try to declare an input with array of string.

vicenteign commented 5 years ago

be careful that you are not defining a type with incorrect characters, i.e: "user_type" or "user.type". GraphQL only accepts camelCase (UserType) in their definitions. @sangdth If you want to declare an array, try "users: [String!]!".

sangdth commented 5 years ago

Thank you, I did not return the array in @field, that was why it yells about that. Added @Field(() => [String]) fixed the problem.

Spartano commented 4 years ago

I have the same error than @peterbabic when I run npm run start

ziaenezhad commented 4 years ago

I still have this issue:

"dependencies": {
    "@nestjs/common": "^6.10.14",
    "@nestjs/config": "^0.1.0",
    "@nestjs/core": "^6.10.14",
    "@nestjs/graphql": "^6.5.3",
    "@nestjs/platform-express": "^6.10.14",
    "apollo-server-core": "^2.9.16",
    "apollo-server-express": "^2.9.16",
    "graphql": "^14.6.0",
    "graphql-tools": "^4.0.6",
    "prisma-binding": "^2.3.16",
    "prisma-client-lib": "^1.34.10",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.0",
    "rxjs": "^6.5.4",
    "type-graphql": "^0.17.6"
  }
lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.