`graphql-typegraphql` example has build errors out of the box
codyleftwich opened this issue · comments
Attempting to call tsc --build
on a freshly copied project will have a couple of compilation errors.
- An error with the
validator
module. This seems to be related to upgradingclass-validator
to version0.13.2
- An error in the
UserResolver
.
Error log
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsAlphanumeric.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsDecimal.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsCurrency.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsEmail.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsFQDN.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsMacAddress.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsISO8601.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsMobilePhone.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsUrl.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsHash.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsISSN.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsDateString.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsNumberString.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsIdentityCard.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
node_modules/class-validator/types/decorator/string/IsPostalCode.d.ts(2,25): error TS7016: Could not find a declaration file for module 'validator'. '/Git/graphql-typegraphql/node_modules/validator/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/validator` if it exists or add a new declaration (.d.ts) file containing `declare module 'validator';`
src/UserResolver.ts(43,5): error TS2322: Type 'Post[] | null' is not assignable to type 'Post[]'.
Type 'null' is not assignable to type 'Post[]'.
Reproduction steps
- Download the example:
curl https://codeload.github.com/prisma/prisma-examples/tar.gz/latest | tar -xz --strip=2 prisma-examples-latest/typescript/graphql-typegraphql
- Download the necessary packages:
npm install
- Attempt to compile using the typescript compiler:
npx tsc --build
Suggested Fixes
- For the
validator
error:- Using the command in the error log clears things up:
npm i --save-dev @types/validator
- Not suggested: Downgrading to
class-validator 0.13.1
works, but there is a vulnerability
- Using the command in the error log clears things up:
- For the
UserResolver.ts
error, change the return type to Promise<Post[] | null> on line 42.
Hey 👋🏽
Thanks for pointing this out. I think this came up after v4.4.0 where we fixed the types that are returned when we changed the return types when using the Fluent API. I've created a PR to fix this.
Also, I think we'll add a step to transpile/ build the examples to make sure they work :)