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

GraphQL scalars output type not determined when coming from node_modules/ #1386

Closed johnnyomair closed 3 years ago

johnnyomair commented 3 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

When using GraphQL scalars (e.g. ID) in resolvers placed inside a library (therefore imported from node_modules/), Nest fails to determine the output type:

Error: Cannot determine a GraphQL output type for the "simpleScalar". Make sure your class is decorated with an appropriate decorator.

Using a String works perfectly fine.

Expected behavior

Nest correctly determines the output type.

Minimal reproduction of the problem with instructions

https://github.com/johnnyomair/nestjs-graphql-scalar-demo

Steps

  1. Build library cd lib/ && npm install && npm run build
  2. Run application cd test/ && npm install && npm start:dev

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

I can't use GraphQL scalars (ID, Int and Float) in my library package.

Environment


Nest version: 7.5.1 (@nestjs/graphql at 7.9.9)

For Tooling issues:
- Node version: 10.23.3
- Platform:  Mac

Others:

Might be related to: https://github.com/nestjs/graphql/issues/781

kamilmysliwiec commented 3 years ago

Your @nestjs/{...} deps must be defined as peer dependencies. Otherwise, both your lib and application will have a dedicated, local copy of these packages in the node_modules folder (lib/node_modules/@nestjs/graphql/{random-class} !== test/node_modules/@nestjs/graphql/{random-class}).

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

Dannus90 commented 2 months ago

I can add to this that if anyone runs into an issue when using npm link having a service for example using a package with @nestjs/graphql which in turns uses another package having @nestjs/graphql. The answer above won't solve it for running locally. This is an issue with how npm link works and I suggest to try yalc instead.

Link references the entire source code with node_modules which basically makes the package used by this package to reference @nestjs/graphql there instead of the service causing the same issue as stated above. Yalc works differently and does not cause this issue.