graphql-nexus / nexus-plugin-prisma

Deprecated
MIT License
828 stars 118 forks source link

Type 'InputName' cannot be used to index type 'NexusPrismaInputs[ModelName][MethodName]'. s #664

Open emroot opened 4 years ago

emroot commented 4 years ago

I just started getting this error. Out of the blue. I'm suspecting it might have to do my node_modules.

src/generated/nexus-types.ts(70,7): error TS2536: Type 'InputName' cannot be used to index type 'NexusPrismaInputs[ModelName][MethodName]'.
src/generated/nexus-types.ts(132,15): error TS2344: Type 'GetNexusPrismaInput<ModelName, MethodName, "filtering">' does not satisfy the constraint 'string | number | symbol'.
  Type 'MethodName extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][MethodName]["filtering"] : never' is not assignable to type 'string | number | symbol'.
    Type 'NexusPrismaInputs[ModelName][MethodName]["filtering"]' is not assignable to type 'string | number | symbol'.
      Type 'NexusPrismaInputs[ModelName][string]["filtering"] | NexusPrismaInputs[ModelName][number]["filtering"] | NexusPrismaInputs[ModelName][symbol]["filtering"]' is not assignable to type 'string | number | symbol'.
        Type 'NexusPrismaInputs[ModelName][string]["filtering"]' is not assignable to type 'string | number | symbol'.
          Type 'NexusPrismaInputs[ModelName][string]["filtering"]' is not assignable to type 'symbol'.
            Type 'NexusPrismaInputs[ModelName][MethodName]["filtering"]' is not assignable to type 'symbol'.
              Type 'unknown extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["filtering"] : never' is not assignable to type 'string | number | symbol'.
                Type 'NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["filtering"]' is not assignable to type 'string | number | symbol'.
                  Type 'NexusPrismaInputs[ModelName][string]["filtering"] | NexusPrismaInputs[ModelName][number]["filtering"] | NexusPrismaInputs[ModelName][symbol]["filtering"]' is not assignable to type 'string | number | symbol'.
                    Type 'NexusPrismaInputs[ModelName][string]["filtering"]' is not assignable to type 'string | number | symbol'.
                      Type 'NexusPrismaInputs[ModelName][string]["filtering"]' is not assignable to type 'symbol'.
                        Type 'NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["filtering"]' is not assignable to type 'symbol'.
                          Type 'unknown extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["filtering"] : never' is not assignable to type 'symbol'.
                            Type 'MethodName extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][MethodName]["filtering"] : never' is not assignable to type 'symbol'.
                              Type 'GetNexusPrismaInput<ModelName, MethodName, "filtering">' is not assignable to type 'symbol'.
                                Type 'MethodName extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][MethodName]["filtering"] : never' is not assignable to type 'symbol'.
                                  Type 'NexusPrismaInputs[ModelName][MethodName]["filtering"]' is not assignable to type 'symbol'.
                                    Type 'NexusPrismaInputs[ModelName][string]["filtering"] | NexusPrismaInputs[ModelName][number]["filtering"] | NexusPrismaInputs[ModelName][symbol]["filtering"]' is not assignable to type 'symbol'.
                                      Type 'NexusPrismaInputs[ModelName][string]["filtering"]' is not assignable to type 'symbol'.
                                        Type 'unknown extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["filtering"] : never' is not assignable to type 'symbol'.
                                          Type 'NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["filtering"]' is not assignable to type 'symbol'.
                                            Type 'NexusPrismaInputs[ModelName][string]["filtering"] | NexusPrismaInputs[ModelName][number]["filtering"] | NexusPrismaInputs[ModelName][symbol]["filtering"]' is not assignable to type 'symbol'.
                                              Type 'NexusPrismaInputs[ModelName][string]["filtering"]' is not assignable to type 'symbol'.
src/generated/nexus-types.ts(140,15): error TS2344: Type 'GetNexusPrismaInput<ModelName, MethodName, "ordering">' does not satisfy the constraint 'string | number | symbol'.
  Type 'MethodName extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][MethodName]["ordering"] : never' is not assignable to type 'string | number | symbol'.
    Type 'NexusPrismaInputs[ModelName][MethodName]["ordering"]' is not assignable to type 'string | number | symbol'.
      Type 'NexusPrismaInputs[ModelName][string]["ordering"] | NexusPrismaInputs[ModelName][number]["ordering"] | NexusPrismaInputs[ModelName][symbol]["ordering"]' is not assignable to type 'string | number | symbol'.
        Type 'NexusPrismaInputs[ModelName][string]["ordering"]' is not assignable to type 'string | number | symbol'.
          Type 'NexusPrismaInputs[ModelName][string]["ordering"]' is not assignable to type 'symbol'.
            Type 'NexusPrismaInputs[ModelName][MethodName]["ordering"]' is not assignable to type 'symbol'.
              Type 'unknown extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["ordering"] : never' is not assignable to type 'string | number | symbol'.
                Type 'NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["ordering"]' is not assignable to type 'string | number | symbol'.
                  Type 'NexusPrismaInputs[ModelName][string]["ordering"] | NexusPrismaInputs[ModelName][number]["ordering"] | NexusPrismaInputs[ModelName][symbol]["ordering"]' is not assignable to type 'string | number | symbol'.
                    Type 'NexusPrismaInputs[ModelName][string]["ordering"]' is not assignable to type 'string | number | symbol'.
                      Type 'NexusPrismaInputs[ModelName][string]["ordering"]' is not assignable to type 'symbol'.
                        Type 'NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["ordering"]' is not assignable to type 'symbol'.
                          Type 'unknown extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["ordering"] : never' is not assignable to type 'symbol'.
                            Type 'MethodName extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][MethodName]["ordering"] : never' is not assignable to type 'symbol'.
                              Type 'GetNexusPrismaInput<ModelName, MethodName, "ordering">' is not assignable to type 'symbol'.
                                Type 'MethodName extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][MethodName]["ordering"] : never' is not assignable to type 'symbol'.
                                  Type 'NexusPrismaInputs[ModelName][MethodName]["ordering"]' is not assignable to type 'symbol'.
                                    Type 'NexusPrismaInputs[ModelName][string]["ordering"] | NexusPrismaInputs[ModelName][number]["ordering"] | NexusPrismaInputs[ModelName][symbol]["ordering"]' is not assignable to type 'symbol'.
                                      Type 'NexusPrismaInputs[ModelName][string]["ordering"]' is not assignable to type 'symbol'.
                                        Type 'unknown extends keyof NexusPrismaInputs[ModelName] ? NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["ordering"] : never' is not assignable to type 'symbol'.
                                          Type 'NexusPrismaInputs[ModelName][keyof NexusPrismaInputs[ModelName]]["ordering"]' is not assignable to type 'symbol'.
                                            Type 'NexusPrismaInputs[ModelName][string]["ordering"] | NexusPrismaInputs[ModelName][number]["ordering"] | NexusPrismaInputs[ModelName][symbol]["ordering"]' is not assignable to type 'symbol'.
                                              Type 'NexusPrismaInputs[ModelName][string]["ordering"]' is not assignable to type 'symbol'.

my package.json

"dependencies": {
    "@graphql-codegen/typescript": "^1.12.2",
    "@graphql-codegen/typescript-resolvers": "^1.12.2",
    "@nexus/schema": "^0.13.1",
    "@prisma/client": "^2.0.0-beta.4",
    "graphql-yoga": "^1.18.3",
    "nexus": "^0.12.0-rc.13",
    "nexus-prisma": "^0.11.1",
    "ts-node": "^8.6.2",
    "typescript": "^3.8.3",
  },
"devDependencies": {
    "@graphql-codegen/cli": "^1.12.2",
    "@prisma/cli": "^2.0.0-beta.4",
    "@typescript-eslint/eslint-plugin": "^2.27.0",
    "@typescript-eslint/parser": "^2.28.0",
    "graphql-cli": "^3.0.14",
    "nodemon": "^2.0.2",
    "prettier": "^2.0.4",
    "ts-node-dev": "^1.0.0-pre.44",
    "typescript": "^3.8.3"
  },
moderndegree commented 4 years ago

I've been trying to debug this same issue over the past few hours.

"dependencies": {
    "@nexus/schema": "^0.13.1",
    "@prisma/client": "2.0.0-beta.4",
    "apollo-server": "^2.13.0",
    "apollo-server-express": "^2.13.0",
    "bcrypt": "^4.0.1",
    "graphql": "14.5.0",
    "jsonwebtoken": "^8.5.1",
    "nexus": "^0.21.0",
    "nexus-prisma": "^0.13.0"
  },
  "devDependencies": {
    "@prisma/cli": "2.0.0-beta.4",
    "@types/bcrypt": "^3.0.0",
    "@types/jsonwebtoken": "^8.3.9",
    "ts-node": "^8.10.1",
    "ts-node-dev": "^1.0.0-pre.44",
    "typescript": "^3.9.2"
  }
emroot commented 4 years ago

@moderndegree This is how I solved my issue:

Before in my scheme.ts, this is how things looked like:

export const schema = makeSchema({
  types: [
    ...
  ],
  plugins: [
    // @ts-ignore
    nexusPrismaPlugin({
      outputs: {
        typegen: join(__dirname, '/generated/nexus-types.ts'),
      },
    }),
  ],
  outputs: {
    schema: join(__dirname, '/schema.graphql'),
    typegen: join(__dirname, '/generated/nexus.ts'),
  },
  typegenAutoConfig: {
    contextType: 't.GraphqlContext',
    sources: [
      {
        source: '@prisma/client',
        alias: 'prisma',
      },
      {
        source: require.resolve('./types'),
        alias: 't',
      },
    ],
  },
});

I added this to my tsconfig.json

"skipLibCheck": true

and made sure to delete the old typescript generated nexus files and instead generate definition files by renaming my old files nexus*.tsnexus*.d.ts

export const schema = makeSchema({
  types: [
    ...
  ],
  plugins: [
    // @ts-ignore
    nexusPrismaPlugin({
      outputs: {
        typegen: join(__dirname, '/generated/nexus-types.d.ts'),
      },
    }),
  ],
  outputs: {
    schema: join(__dirname, '/schema.graphql'),
    typegen: join(__dirname, '/generated/nexus.d.ts'),
  },
  typegenAutoConfig: {
    contextType: 't.GraphqlContext',
    sources: [
      {
        source: '@prisma/client',
        alias: 'prisma',
      },
      {
        source: require.resolve('./types'),
        alias: 't',
      },
    ],
  },
});
moderndegree commented 4 years ago

Thanks for the tip. Unfortunately,this solution disables some of the beneficial type checking that TypeScript affords us. It unblocks me but I would love to see this issue resolved.

moderndegree commented 4 years ago

@emroot I am still testing my theory but I am 99% sure the problem is with the typescript version. If I change ^3.8.3 to 3.8.3, it seems to fix the issue. Without locking the version down, we end up getting 3.9.2, which is apparently not compatible.

There were definitely some breaking changes in 3.9 that could cause these issues: https://github.com/microsoft/TypeScript/wiki/Breaking-Changes

jfschwarz commented 4 years ago

Can confirm @moderndegree observation: I also started seeing this problem after upgrading TypeScript from 3.8 to 3.9.