graphql-nexus / nexus-plugin-prisma

Deprecated
MIT License
828 stars 118 forks source link

Cannot read property 'nexus' of undefined #562

Closed malekjaroslav closed 4 years ago

malekjaroslav commented 4 years ago

Getting this error. What I found is that after calling makeSchema, the schema does not include extensions and that is where it fails...

TypeError: Cannot read property 'nexus' of undefined
    at TypegenPrinter.resolveBackingType (/Users/macbookpro/Sites/Qusion/cms
/backend/node_modules/nexus/src/typegenPrinter.ts:451:47)
    at hasFields.concat.concat.concat.concat.forEach (/Users/macbookpro/Site
s/Qusion/cms/backend/node_modules/nexus/src/typegenPrinter.ts:405:33)
    at Array.forEach (<anonymous>)
    at TypegenPrinter.buildRootTypeMap (/Users/macbookpro/Sites/Qusion/cms/b
ackend/node_modules/nexus/src/typegenPrinter.ts:404:8)
    at TypegenPrinter.printRootTypeMap (/Users/macbookpro/Sites/Qusion/cms/b
ackend/node_modules/nexus/src/typegenPrinter.ts:490:12)
    at TypegenPrinter.print (/Users/macbookpro/Sites/Qusion/cms/backend/node
_modules/nexus/src/typegenPrinter.ts:87:12)
    at TypegenMetadata.<anonymous> (/Users/macbookpro/Sites/Qusion/cms/backe
nd/node_modules/nexus/src/typegenMetadata.ts:142:8)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/macbookpro/Sites/Qusion/cms/backend/node_modules/tslib/tslib.js:107:62)
const schema = makeSchema({
    types: [types],
    plugins: [nexusPrismaPlugin()],
    outputs: {
      schema: path.resolve("src/generated/schema.graphql"),
      typegen: path.resolve("src/generated/nexus.ts")
    },
    typegenAutoConfig: {
      contextType: "context.Context",
      sources: [
        {
          source: "@prisma/photon",
          alias: "prisma"
        },
        {
          alias: "context",
          source: path.resolve("src/modules/context.ts")
        }
      ]
    }
  });
jasonkuhrt commented 4 years ago

I think this is a nexus issue? Also are you using the latest version of nexus and graphql libs?

Sent with GitHawk

ZaneH commented 4 years ago

FIXED

I added:

"workspaces": {
  "nohoist": ["**"]
}

to the child project, ran yarn and yarn generate! Yeet 🎉


I tried to mirror the Prisma2 example package.json and now I'm getting this after upgrading to preview019:

Crash Log

Toggle me ```bash [4/4] 🔨 Building fresh packages... success Saved lockfile. $ npm -s run generate > Downloading Prisma engines for darwin [====================] 100% Generating Photon.js to ./../../node_modules/@prisma/photon Done in 21.56s [info] Logger starting with log-level: debug TypeError: Cannot read property 'nexus' of undefined at TypegenPrinter.resolveBackingType (/Users/zane/repos/mono-repo_6/node_modules/nexus/src/typegenPrinter.ts:451:47) at groupedTypes.enum.forEach (/Users/zane/repos/mono-repo_6/node_modules/nexus/src/typegenPrinter.ts:357:32) at Array.forEach () at TypegenPrinter.buildEnumTypeMap (/Users/zane/repos/mono-repo_6/node_modules/nexus/src/typegenPrinter.ts:356:28) at TypegenPrinter.printEnumTypeMap (/Users/zane/repos/mono-repo_6/node_modules/nexus/src/typegenPrinter.ts:388:58) at TypegenPrinter.print (/Users/zane/repos/mono-repo_6/node_modules/nexus/src/typegenPrinter.ts:86:12) at TypegenMetadata. (/Users/zane/repos/mono-repo_6/node_modules/nexus/src/typegenMetadata.ts:142:8) at Generator.next () at fulfilled (/Users/zane/repos/mono-repo_6/node_modules/tslib/tslib.js:107:62) ✨ Done in 134.21s. ```

package.json

packages/prisma/package.json

```json { "name": "api", "version": "0.1.0", "private": true, "scripts": { "start": "ts-node-dev --no-notify --respawn --transpileOnly src/server", "clean": "rm -rf dist", "build": "npm -s run clean && npm -s run generate && tsc", "generate": "npm -s run generate:prisma && npm -s run generate:nexus", "generate:prisma": "prisma2 generate", "generate:nexus": "ts-node --transpile-only src/schema", "seed": "ts-node prisma/seed.ts 348", "postinstall": "npm -s run generate" }, "dependencies": { "@prisma/photon": "2.0.0-preview019", "bcryptjs": "2.4.3", "graphql-middleware": "4.0.1", "graphql-shield": "5.7.3", "graphql-yoga": "1.18.3", "jsonwebtoken": "^8.5.1", "nexus": "0.12.0-rc.5", "nexus-prisma": "0.6.1", "pg": "^7.15.0", }, "devDependencies": { "@prisma/sdk": "0.0.105", "@types/bcryptjs": "2.4.2", "@types/jsonwebtoken": "8.3.4", "@types/node": "12.7.5", "@types/pg": "^7.11.2", "prisma2": "2.0.0-preview019", "ts-node": "8.5.4", "ts-node-dev": "1.0.0-pre.44", "typescript": "^3.7.2" } } ```


Additional Info

malekjaroslav commented 4 years ago

@jasonkuhrt Thank you! I did not realize the issue could be older graphql libs. I updated all and it now works :)