paljs/create-nexus-type

TypeError: Cannot read property 'includes' of undefined

ScottWallace opened this issue · 12 comments

Getting the following error while processing the Prisma2 schema shown below. When I remove the Comment and Mention models from the schema, it works fine.

The Prisma2 schema below works fine using prisma2 dev and prisma2 lift under Preview 19, but fails using cnt.

Command:
npx cnt -mq -f -o --js --mjs

Error:

/Users/scottwallace/Developer/hushright/graphql/node_modules/create-nexus-type/src/cli.js:81
					} else if (fileContent !== '' && !filteredArray[0].includes('//')) {
					                                                   ^

TypeError: Cannot read property 'includes' of undefined
    at lines.map.line (/Users/scottwallace/Developer/hushright/graphql/node_modules/create-nexus-type/src/cli.js:81:57)
    at Array.map (<anonymous>)
    at /Users/scottwallace/Developer/hushright/graphql/node_modules/create-nexus-type/src/cli.js:43:10
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)

Prisma Schema:

generator photon {
  provider = "photonjs"
}

datasource db {
  provider = "mysql"
  url      = "[redacted connection url]"
}

model User {
  id Int @id @default(autoincrement())

  displayname String @unique
  uid String @unique
  photoURL  String
  description String?

  following User[] @relation("follow")
  followedBy User[] @relation("follow")
  posts Post[]
  emotions Emotion[]
  shares Share[]

  mentionsOfUser Mention[] @relation("mentionsOfUser")
  mentionsOfBy Mention[] @relation("mentionsByUser")

  pagerank Float @default(0)
  emotionalScore Float @default(0)

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  deletedAt DateTime?
  deleted Boolean @default(false)
  blocked Boolean @default(false)
  blockedOn DateTime?
}


model  Post {
  id Int @id @default(autoincrement())

  author User
  text String

  links WebLink[]
  hashtags Hashtag[]
  comments Comment[]
  images Image[]
  emotions Emotion[]
  shares Share[]
  mentions Mention[]

  pagerank Float @default(0)
  emotionalScore Float @default(0)

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  deletedAt DateTime?
  deleted Boolean @default(false)
}


model WebLink {
  id Int @id @default(autoincrement())

  orginalUrl String
  href String
  hostname String
  secure Boolean
  origin String
  validated Boolean @default(false)

  pagerank Float @default(0)

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  deletedAt DateTime?
  deleted Boolean @default(false)
}


model Emotion {
  id Int @id @default(autoincrement())

  emotionType Int @default(0)
  score Int @default(0)

  emoter User

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  deletedAt DateTime?
  deleted Boolean @default(false)
}


model Hashtag {
  id Int @id @default(autoincrement())

  name String

  pagerank Float @default(0)

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  deletedAt DateTime?
  deleted Boolean @default(false)
}


model Image {
  id Int @id @default(autoincrement())

  url String
  validated Boolean @default(false)

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  deletedAt DateTime?
  deleted Boolean @default(false)
}


model Share {
  id Int @id @default(autoincrement())

  sharer User

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  deletedAt DateTime?
  deleted Boolean @default(false)
}


model Comment {
  id Int @id @default(autoincrement())
  
  body String

  pagerank Float @default(0)
  emotionalScore Float @default(0)

  author User
  post Post
  links WebLink[]
  hashtags Hashtag[]
  images Image[]
  emotions Emotion[]
  mentions Mention[]

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  deletedAt DateTime?
  deleted Boolean @default(false)
}

model Mention {
  id Int @id @default(autoincrement())

  ofUser User @relation("mentionsOfUser")
  byUser User @relation("mentionsByUser")
  inPost Post?
  inComment Comment?
  
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  deletedAt DateTime?
  deleted Boolean @default(false)
}

Any help appreciated.

Hi @ScottWallace ,

You need to use one flag for js --js or --mjs not two
Try this please

@vitaliytv can you see this error in your pull need to make if pass two flags use one of them not two

No difference, same error.

ok this model here you share is made this error or the model with comment ?? can you show me how you write comments

I'm sorry if I wasn't clear. The error described is when I run the command npx cnt -mq -f -o --js in bash, against my schema.prisma file.

When I edit the schema.prisma file to remove the Comment and Mention models, cnt returns with Created files success, though, of course, the Comment and Mention models are absent.

Naturally, I could hand-create the missing Comment and Mention models, but that would strongly interfere with the development process. I'm hoping to use ctx as part of the build process.

I am not yet to a point where I can "write comments", because I need the nexus models created first, so that I can then use them in Apollo Server. None of my code, generated or otherwise, is being executed anywhere, I'm only attempting to use cnt to create the Nexus models from the Prisma2 schema.

Just to be more clear, cnt seems to process through the schema as far as the model Share, then fails, never creating the Comment or Mention files.

it's working very good and this out of

// Mention.js file
import nexus from 'nexus'
const { objectType, extendType } = nexus
					
export const Mention = objectType({
  name: 'Mention',
  definition(t) {
    t.model.id()
    t.model.ofUser()
    t.model.byUser()
    t.model.inPost()
    t.model.inComment()
    t.model.createdAt()
    t.model.updatedAt()
    t.model.deletedAt()
    t.model.deleted()
  },
})

export const mentionQuery = extendType({
  type: 'Query',
  definition(t) {
    t.crud.mention()
    t.crud.mentions({ filtering: true, ordering: true })
  },
})

export const mentionMutation = extendType({
  type: 'Mutation',
  definition(t) {
    t.crud.createOneMention()
    t.crud.updateOneMention()
    t.crud.upsertOneMention()
    t.crud.deleteOneMention()

    t.crud.updateManyMention()
    t.crud.deleteManyMention()
  },
})
// Comment.js
import nexus from 'nexus'
const { objectType, extendType } = nexus
					
export const Comment = objectType({
  name: 'Comment',
  definition(t) {
    t.model.id()
    t.model.body()
    t.model.pagerank()
    t.model.emotionalScore()
    t.model.author()
    t.model.post()
    t.model.links()
    t.model.hashtags()
    t.model.images()
    t.model.emotions()
    t.model.mentions()
    t.model.createdAt()
    t.model.updatedAt()
    t.model.deletedAt()
    t.model.deleted()
  },
})

export const commentQuery = extendType({
  type: 'Query',
  definition(t) {
    t.crud.comment()
    t.crud.comments({ filtering: true, ordering: true })
  },
})

export const commentMutation = extendType({
  type: 'Mutation',
  definition(t) {
    t.crud.createOneComment()
    t.crud.updateOneComment()
    t.crud.upsertOneComment()
    t.crud.deleteOneComment()

    t.crud.updateManyComment()
    t.crud.deleteManyComment()
  },
})

I wish that were the case for me. Here's some stats on my setup:

macOS: 10.15.2 (Catalina)
zsh shell (default for Catalina)
Node 10.17.0 via nvm
nvm 6.11.3
"nexus-prisma": "^0.7.0-next.1"
"@prisma/photon": "2.0.0-preview019"
"devDependencies": {
"create-nexus-type": "^1.1.3"
}

Don't know what else to try.

go here https://whereby.com/ahmedelywa to see your screen

Thanks for the offer, but I'm in a facility that prohibits such things.

@vitaliytv can you see this error in your pull need to make if pass two flags use one of them not two

i don't see error

@vitaliytv
i get the error in this
image
add else for next if because you mess it and this add js export to mjs and ts