graphql icon indicating copy to clipboard operation
graphql copied to clipboard

Unused `ObjectType` referencing custom scalar results in error during schema generation

Open SimonCockx opened this issue 3 years ago • 1 comments

Current behavior

When I define a custom scalar (e.g., @Scalar('MyCustomScalar')) which I reference in an ObjectType that isn't exposed through any resolver, I run into an error Error: "MyCustomScalar" defined in resolvers, but not in schema during schema generation.

Minimum reproduction code

https://github.com/SimonCockx/nest-gql-scalar-bug

Steps to reproduce

  1. Clone https://github.com/SimonCockx/nest-gql-scalar-bug
  2. npm install
  3. nest start See error.

Expected behavior

I would expect one of these two:

  1. @nestjs/graphql successfully determines that the custom scalar is not necessary, so it does not generate it in the schema, but it also doesn't produce an error (which is the case now).
  2. @nestjs/graphql just generates the scalar without detecting whether it is referenced in some way. (probably simpler, but I saw the current code already does some reference detection to find only necessary types, so option (1) might be better)

Package version

10.0.16

Graphql version

graphql: 16.5.0 apollo-server-express: 3.9.0

NestJS version

8.0.0

Node.js version

16.15.1

In which operating systems have you tested?

  • [ ] macOS
  • [X] Windows
  • [ ] Linux

SimonCockx avatar Jun 19 '22 16:06 SimonCockx

Same issue for me It fails on tests but runs fine on dev server

iamkhalidbashir avatar Aug 27 '22 06:08 iamkhalidbashir

I can confirm, it still occurs in latest. I've opened a PR with a potential fix.

rickdgeerling avatar Oct 01 '22 19:10 rickdgeerling

Let's track this here https://github.com/nestjs/graphql/pull/2428

kamilmysliwiec avatar Oct 03 '22 07:10 kamilmysliwiec