Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Make Prisma TS client work in strict mode without needing to explicitly add @types/graphql. #3619

Closed
nikolasburk opened this issue Nov 28, 2018 · 3 comments

Comments

@nikolasburk
Copy link
Member

The TS should be able to be used in strict mode with only the prisma-client-lib dependency. Right now it doesn't work because (presumably) the @types/graphql dep is missing.

For example, for this setup:

package.json

{
  "name": "script",
  "license": "MIT",
  "dependencies": {
    "prisma-client-lib": "1.21.1"
  },
  "devDependencies": {
    "ts-node": "7.0.1",
    "typescript": "3.1.6"
  },
  "scripts": {
    "start": "ts-node src/script.ts"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "sourceMap": true,
    "outDir": "dist",
    "strict": true,
    "lib": ["esnext", "dom"]
  }
}

I am always getting this error:

$ yarn tsc
yarn run v1.12.3
$ /Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/.bin/tsc
node_modules/apollo-link/lib/types.d.ts:2:47 - error TS7016: Could not find a declaration file for module 'graphql'. '/Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/graphql/index.js' implicitly has an 'any' type.
  Try `npm install @types/graphql` if it exists or add a new declaration (.d.ts) file containing `declare module 'graphql';`

2 import { ExecutionResult, DocumentNode } from 'graphql';
                                                ~~~~~~~~~

node_modules/prisma-client-lib/dist/Client.d.ts:2:64 - error TS7016: Could not find a declaration file for module 'graphql'. '/Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/graphql/index.js' implicitly has an 'any' type.
  Try `npm install @types/graphql` if it exists or add a new declaration (.d.ts) file containing `declare module 'graphql';`

2 import { OperationTypeNode, GraphQLField, GraphQLSchema } from 'graphql';
                                                                 ~~~~~~~~~

node_modules/prisma-client-lib/dist/codegen/Generator.d.ts:1:31 - error TS7016: Could not find a declaration file for module 'graphql'. '/Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/graphql/index.js' implicitly has an 'any' type.
  Try `npm install @types/graphql` if it exists or add a new declaration (.d.ts) file containing `declare module 'graphql';`

1 import { GraphQLSchema } from 'graphql';
                                ~~~~~~~~~

node_modules/prisma-client-lib/dist/codegen/go-client.d.ts:2:190 - error TS7016: Could not find a declaration file for module 'graphql'. '/Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/graphql/index.js' implicitly has an 'any' type.
  Try `npm install @types/graphql` if it exists or add a new declaration (.d.ts) file containing `declare module 'graphql';`

2 import { GraphQLUnionType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLScalarType, GraphQLEnumType, GraphQLObjectTypeas GraphQLObjectTypeRef, GraphQLField, GraphQLArgument } from 'graphql';
                                                              ~~~~~~~~~

node_modules/prisma-client-lib/dist/codegen/typescript-client.d.ts:1:265 - error TS7016: Could not find a declaration file for module 'graphql'. '/Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/graphql/index.js' implicitly has an 'any' type.
  Try `npm install @types/graphql` if it exists or add a new declaration (.d.ts) file containing `declare module 'graphql';`

1 import { GraphQLObjectType, GraphQLUnionType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLInputField, GraphQLField, GraphQLInputType, GraphQLOutputType, GraphQLScalarType, GraphQLEnumType, GraphQLFieldMap, GraphQLObjectType as GraphQLObjectTypeRef } from 'graphql';
        ~~~~~~~~~

node_modules/prisma-client-lib/dist/types.d.ts:1:36 - error TS7016: Could not find a declaration file for module 'graphql'. '/Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/graphql/index.js' implicitly has an 'any' type.
  Try `npm install @types/graphql` if it exists or add a new declaration (.d.ts) file containing `declare module 'graphql';`

1 import { GraphQLResolveInfo } from 'graphql';
                                     ~~~~~~~~~

node_modules/subscriptions-transport-ws/dist/client.d.ts:2:33 - error TS7016: Could not find a declaration file for module 'graphql/execution/execute'. '/Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/graphql/execution/execute.js' implicitly has an 'any' type.
  Try `npm install @types/graphql` if it exists or add a new declaration (.d.ts) file containing `declare module 'graphql/execution/execute';`

2 import { ExecutionResult } from 'graphql/execution/execute';
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/subscriptions-transport-ws/dist/client.d.ts:3:30 - error TS7016: Could not find a declaration file for module 'graphql/language/ast'. '/Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/graphql/language/ast.js' implicitly has an 'any' type.
  Try `npm install @types/graphql` if it exists or add a new declaration (.d.ts) file containing `declare module 'graphql/language/ast';`

3 import { DocumentNode } from 'graphql/language/ast';
                               ~~~~~~~~~~~~~~~~~~~~~~

node_modules/subscriptions-transport-ws/dist/server.d.ts:2:28 - error TS7016: Could not find a declaration file for module 'ws'.'/Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/subscriptions-transport-ws/node_modules/ws/index.js' implicitly has an 'any' type.
  Try `npm install @types/ws` if it exists or add a new declaration (.d.ts) file containing `declare module 'ws';`

2 import * as WebSocket from 'ws';
                             ~~~~

node_modules/subscriptions-transport-ws/dist/server.d.ts:3:103 - error TS7016: Could not find a declaration file for module 'graphql'. '/Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/graphql/index.js' implicitly has an 'any'type.
  Try `npm install @types/graphql` if it exists or add a new declaration (.d.ts) file containing `declare module 'graphql';`

3 import { ExecutionResult, GraphQLSchema, DocumentNode, ValidationContext, GraphQLFieldResolver } from 'graphql';
                                                                                                        ~~~~~~~~~

src/generated/prisma-client/index.ts:5:45 - error TS7016: Could not find a declaration file for module 'graphql'. '/Users/nikolasburk/prisma/github/prisma-examples/typescript/script/node_modules/graphql/index.js' implicitly has an 'any' type.
  Try `npm install @types/graphql` if it exists or add a new declaration (.d.ts) file containing `declare module 'graphql';`

5 import { DocumentNode, GraphQLSchema } from "graphql";
                                              ~~~~~~~~~

error Command failed with exit code 2.
@schickling
Copy link
Member

We should double-check whether it's really the right decision to bundle graphql and @types/graphql with prisma-client-lib. According to this article by Lee Byron graphql should be part of peerDependencies unless we're able to figure out a way to "tree-shake out" what we need so that it doesn't conflict with other graphql installations.

image

@schickling
Copy link
Member

Note that @types/graphql should be added as a real dependency (see microsoft/types-publisher#81).

@divyenduz
Copy link
Contributor

This is not possible because multiple versions of graphql package cannot exist in the same project.

For example, if a project mandatorily depends on graphql v0.13.x (say) for any reasons and they cannot upgrade and we ship a client version with the latest graphql v14.x (at the time of writing) then this will break their project.

I am closing this issue, please ping me if you feel strongly against closing it or if you think that this should be reopened for further research like actually "tree-shaking" out the relevant parts from graphql package to allow independent graphql version installations.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants