Describe the bug
I just started a brand new project with graphql-yoga and prisma 0.19. The generated TypeScript client starts with
import { DocumentNode, GraphQLSchema } from "graphql";
import { IResolvers } from "graphql-tools/dist/Interfaces";
import { makePrismaClientClass, BaseClientOptions } from "prisma-client-lib";
import { typeDefs } from "./prisma-schema";
which would be fine except that GraphQLSchema and IResolvers are unused, which causes problems if you'd like to enable TypeScript's noUnusedLocals check in your own code. Is there some way that we could get the generated libraries to either compile under the strictest possible options, or just generate them with // @ts-ignore statements in the code?
To Reproduce
Steps to reproduce the behavior:
prisma deploy to generate the TypeScript client library.noUnusedLocals turned on.api [master ?] -> yarn start
yarn run v1.10.1
$ ts-node src/index.ts
/Users/skainswo/dev/kumo/newer-world/api/node_modules/ts-node/src/index.ts:261
return new TSError(diagnosticText, diagnosticCodes)
^
TSError: ⨯ Unable to compile TypeScript:
src/__generated__/prisma/index.ts(5,24): error TS6133: 'GraphQLSchema' is declared but its value is never read.
src/__generated__/prisma/index.ts(6,1): error TS6133: 'IResolvers' is declared but its value is never read.
at createTSError (/Users/skainswo/dev/kumo/newer-world/api/node_modules/ts-node/src/index.ts:261:12)
at getOutput (/Users/skainswo/dev/kumo/newer-world/api/node_modules/ts-node/src/index.ts:367:40)
at Object.compile (/Users/skainswo/dev/kumo/newer-world/api/node_modules/ts-node/src/index.ts:558:11)
at Module.m._compile (/Users/skainswo/dev/kumo/newer-world/api/node_modules/ts-node/src/index.ts:439:43)
at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Object.require.extensions.(anonymous function) [as .ts] (/Users/skainswo/dev/kumo/newer-world/api/node_modules/ts-node/src/index.ts:442:12)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
api [master ?] ->
Expected behavior
The ability to choose arbitrary compile options for my own code, without conflict with the generated prisma client.
Screenshots
n/a
Versions (please complete the following information):
prisma CLI: prisma/1.19.0 (darwin-x64) node-v10.11.0graphql-cli, prisma-binding, graphql-yoga, etc. if applicable "devDependencies": {
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"typescript": "^3.1.3"
},
"dependencies": {
"graphql-yoga": "^1.16.7",
"prisma-client-lib": "^1.19.0"
}
I'm using the following workaround: I removed noUnusedLocals from tsconfig.json and added such rule to tslint.json.
Facing the same situation right now
FWIW my workaround is a python script that manually fixes the generated prisma code:
#!/usr/bin/env python3
# This is a hack to circumvent https://github.com/prisma/prisma/issues/3369. Run
# this script after `prisma deploy` or any other time that the prisma bindings
# are regenerated.
filename = 'src/__generated__/prisma/index.ts'
src = open(filename).read()
f = open(filename, 'w')
f.write(
src
.replace(
'import { DocumentNode, GraphQLSchema } from "graphql";',
'import { DocumentNode } from "graphql";')
.replace(
'import { IResolvers } from "graphql-tools/dist/Interfaces";',
'')
)
f.close()
Fixed in https://github.com/prisma/prisma/commit/10c4361caea857e3005c712d423042788ce1cd64. 🎊 🎉 🎉