graphql
graphql copied to clipboard
Unused `ObjectType` referencing custom scalar results in error during schema generation
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
- Clone
https://github.com/SimonCockx/nest-gql-scalar-bug npm installnest startSee error.
Expected behavior
I would expect one of these two:
@nestjs/graphqlsuccessfully 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).@nestjs/graphqljust 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
Same issue for me It fails on tests but runs fine on dev server
I can confirm, it still occurs in latest. I've opened a PR with a potential fix.
Let's track this here https://github.com/nestjs/graphql/pull/2428