Skip to content

New issue with makeSchema (getTypeMap of undefined) #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ZaneH opened this issue Sep 30, 2020 · 8 comments
Closed

New issue with makeSchema (getTypeMap of undefined) #523

ZaneH opened this issue Sep 30, 2020 · 8 comments

Comments

@ZaneH
Copy link

ZaneH commented Sep 30, 2020

I honestly have no clue where this issue began. Yesterday, at some point, I started getting this error on yarn generate:

yarn run v1.22.5
warning package.json: No license field
$ npm -s run generate:prisma && npm -s run generate:nexus
Environment variables loaded from prisma/.env
Prisma Schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (version: 2.7.0) to ./../../node_modules/@prisma/client in 216ms

You can now start using Prisma Client in your code:

import { PrismaClient } from '@prisma/client'
// or const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()

Explore the full API: http://pris.ly/d/client
TypeError: Cannot read property 'getTypeMap' of undefined
    at generateMiddlewareFromSchemaAndRuleTree (/home/zaneh/Desktop/redacted/node_modules/graphql-shield/src/generator.ts:241:28)
    at MiddlewareGenerator.generator (/home/zaneh/Desktop/redacted/node_modules/graphql-shield/src/generator.ts:293:5)
    at MiddlewareGenerator.generate (/home/zaneh/Desktop/redacted/node_modules/graphql-middleware/src/generator.ts:19:17)
    at middlewares.map.middleware (/home/zaneh/Desktop/redacted/node_modules/graphql-middleware/src/middleware.ts:72:25)
    at Array.map (<anonymous>)
    at applyMiddlewareWithOptions (/home/zaneh/Desktop/redacted/node_modules/graphql-middleware/src/middleware.ts:70:45)
    at applyMiddleware (/home/zaneh/Desktop/redacted/node_modules/graphql-middleware/src/middleware.ts:129:10)
    at new GraphQLServer (/home/zaneh/Desktop/redacted/node_modules/graphql-yoga/src/index.ts:137:13)
    at Object.<anonymous> (/home/zaneh/Desktop/redacted/packages/backend/src/server.ts:28:16)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I can't think of anything that would've caused this, but I tried rolling back to a previous (and known-to-work) commit, deleting my node_modules, and reinstalling, but I never got it back to a working state 🥳. If anyone has any info/debugging tips for this, I'm all ears

My package.json:

{
  "name": "@redacted/backend",
  "version": "1.0.0",
  "scripts": {
    "generate": "npm -s run generate:prisma && npm -s run generate:nexus",
    "generate:prisma": "prisma generate",
    "generate:nexus": "ts-node --transpile-only src/schema",
    "dev": "ts-node-dev --no-notify --respawn --transpileOnly src/server",
    "codegen": "graphql-codegen --config codegen.yml",
    "seed": "ts-node prisma/seed.ts"
  },
  "dependencies": {
    "@nexus/schema": "0.16.0",
    "@paypal/checkout-server-sdk": "^1.0.2",
    "@prisma/client": "2.7.0",
    "@sendgrid/mail": "^7.2.6",
    "aws-sdk": "^2.743.0",
    "bcryptjs": "^2.4.3",
    "cors": "^2.8.5",
    "cuid": "^2.1.8",
    "dotenv-flow": "^3.2.0",
    "graphql": "15.3.0",
    "graphql-iso-date": "^3.6.1",
    "graphql-middleware": "4.0.1",
    "graphql-shield": "7.3.6",
    "graphql-yoga": "1.18.3",
    "lodash": "^4.17.20",
    "multer": "^1.4.2",
    "nexus-plugin-prisma": "0.19.0",
    "sanitize-html": "^2.0.0"
  },
  "devDependencies": {
    "@graphql-codegen/cli": "^1.17.8",
    "@graphql-codegen/typescript": "^1.17.9",
    "@graphql-codegen/typescript-operations": "^1.17.8",
    "@graphql-codegen/typescript-react-apollo": "^2.0.6",
    "@prisma/cli": "2.7.0",
    "@types/aws-sdk": "^2.7.0",
    "@types/bcryptjs": "^2.4.2",
    "@types/cors": "^2.8.7",
    "@types/cuid": "^1.3.1",
    "@types/dotenv-flow": "^3.1.0",
    "@types/graphql-iso-date": "^3.4.0",
    "@types/multer": "^1.4.4",
    "@types/node": "12.12.54",
    "@types/sanitize-html": "^1.27.0",
    "@types/ws": "^7.2.7",
    "ts-node": "9.0.0",
    "ts-node-dev": "1.0.0-pre.50",
    "typescript": "4.0.3"
  }
}

I've tried:

  • Adding and removing the graphql package in package.json
  • console.log(schema) (no output or undefined)
  • Checking the permissions on my project files
  • Resetting my DB (and making sure the connection works)
  • Commenting out large sections of code
  • Using known-to-work package versions from the Prisma examples repo
  • Using a different machine
  • Removing my middleware altogether
  • Following: Repeated errors when trying to update schema facebookarchive/relay-starter-kit#58 (no dice)
  • Ensuring all of my types are included in the schema
@ZaneH

This comment has been minimized.

@ZaneH
Copy link
Author

ZaneH commented Sep 30, 2020

Old news

I'm making progress, but nothing is making sense yet:

yarn run v1.22.5
warning package.json: No license field
$ npm -s run generate:prisma && npm -s run generate:nexus
Environment variables loaded from prisma/.env
Prisma Schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (version: 2.7.0) to ./../../node_modules/@prisma/client in 214ms

You can now start using Prisma Client in your code:

import { PrismaClient } from '@prisma/client'
// or const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()

Explore the full API: http://pris.ly/d/client
# My console.log (logs all of my included types, all of the ones after "index.ts" in the file directory are undefined...):
NexusObjectTypeDef {
  name: 'AuthPayload',
  config: { name: 'AuthPayload', definition: [Function: definition] } } NexusObjectTypeDef {
  name: 'File',
  config: { name: 'File', definition: [Function: definition] } } NexusObjectTypeDef {
  name: 'Image',
  config: { name: 'Image', definition: [Function: definition] } } undefined undefined undefined undefined undefined undefined undefined undefined undefined
Warning: Your GraphQL `File` object definition is projecting a field `product` with `Product` as output type, but `Product` is not defined in your GraphQL Schema

Warning: Your GraphQL `Image` object definition is projecting a field `product` with `Product` as output type, but `Product` is not defined in your GraphQL Schema

Error: 
- Missing type User, did you forget to import a type to the root query?
    at Object.assertNoMissingTypes (/home/zaneh/Desktop/redacted/node_modules/@nexus/schema/src/utils.ts:323:11)
    at Object.makeSchema (/home/zaneh/Desktop/redacted/node_modules/@nexus/schema/src/builder.ts:1524:3)
    at Object.<anonymous> (/home/zaneh/Desktop/redacted/packages/backend/src/server.ts:71:11)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module.m._compile (/home/zaneh/Desktop/redacted/node_modules/ts-node/src/index.ts:1043:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/home/zaneh/Desktop/redacted/node_modules/ts-node/src/index.ts:1046:12)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

So, I removed ./types/index.ts and things started working a little bit better.
Now I'm only missing 1 type. It's the Mutation type. However, I think the issue is rooted deeper than "The Mutation file" because in all of my types, the relational t.model.<other_model>() fields are error'ing.

In addition, I know the code in my type files is correct. It hasn't been changed since my last working commit.

I'm going to pause here. If anyone can help, I'd appreciate it

@ZaneH
Copy link
Author

ZaneH commented Sep 30, 2020

I had this issue earlier: graphql-nexus/nexus-plugin-prisma#872

It transformed into this one

@ZaneH
Copy link
Author

ZaneH commented Oct 2, 2020

Old news

Found the fix! In my Query.ts file, I have references to objects in my generated client.
The issue being: Prisma can't generate the schema, because those objects don't exist.

But they did exist in the past. That's what was tripping me up.

I simply commented out the import, ran yarn generate then yarn codegen (to generate my imported references) and everything is back to a working condition 👍


In addition, the newest version of ts-node-dev causes an issue, I had to use [email protected].

@ZaneH ZaneH closed this as completed Oct 2, 2020
@ZaneH ZaneH reopened this Oct 2, 2020
@ZaneH ZaneH closed this as completed Oct 2, 2020
@ZaneH
Copy link
Author

ZaneH commented Oct 4, 2020

I thought I had fixed this:
I didn't

I believed this to be a case of circular imports (it couldn't generate @prisma/client because a generated type couldn't be imported),

But days after that "fix" I still stumble on this error. Reopened and praying

@ZaneH ZaneH reopened this Oct 4, 2020
@ZaneH
Copy link
Author

ZaneH commented Oct 5, 2020

I think...I maybe found the fix?
I had 2 PrismaClient instances. I exported the 1 in my context.ts file, and removed the one in server.ts. Seems to have fixed it.

@ZaneH ZaneH closed this as completed Oct 5, 2020
@zakthedev
Copy link

How did you fix this at the end? I got the same issue out of a sudden and couldn't get things to work again, I tried different prisma clients from 2.9 up to lastest, please share your package.json if you can

@hyochan
Copy link

hyochan commented Aug 3, 2021

How did you fix this at the end? I got the same issue out of a sudden and couldn't get things to work again, I tried different prisma clients from 2.9 up to lastest, please share your package.json if you can

Try not to import prisma from the context.ts. Pass it through the args. I had this problem earlier.

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

No branches or pull requests

3 participants