GithubHelp home page GithubHelp logo

paljs / create-nexus-type Goto Github PK

View Code? Open in Web Editor NEW
70.0 70.0 4.0 58 KB

This repo moved under pal CLI

Home Page: https://paljs.com/cli/cnt

JavaScript 100.00%
nexus nexus-types prisma typescript-types

create-nexus-type's People

Contributors

ahmedelywa avatar guog avatar renovate-bot avatar simonobe avatar vitaliytv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

create-nexus-type's Issues

Merge generated types with existing ones

Love this tool so far, so thanks for your work here! I was wondering about the possibility of merging in the generated types with existing custom ones that may be unrelated to prisma2.

I see that the current behavior allows me to define additional files in src/types as long as the names don't collide and they won't be overwritten. However, running cnt does overwrite the index.ts file, which forces me to re-export the custom files each time.

Would it be possible to allow for custom types alongside the generated ones in the files, or at least add all files in the types directory back to index.ts once generation has finished?

Field named model inside model fails to generate code

Thanks for a sweet lib. Make stuff easy to work with.

Found an issue with a field name model inside of a model.
Just checked the source fast and I think I saw the issue. Leaving this here for now and dropping a PR if I manage to sort it out later on.

Example not working:

model Car {
  id              Int         @id
  model_year      Int         @default(0)
  license_plate   String       @default("")
  brand           Brand
  model           Model 
}

This works:

model Car {
  id              Int         @id
  model_year      Int         @default(0)
  license_plate   String       @default("")
  brand           Brand
  car_model           Model
}

Comment lines are not ignored

schema:

/// DEMO
model Some {
  /// PK
  id        String     @default(cuid()) @id
  /// MARK
  remark    String?
}

output:

import { objectType, extendType } from 'nexus'

export const Some = objectType({
  name: 'Some',
  definition(t) {
    t.model.///()
    t.model.id()
    t.model.///()
    t.model.remark()
  },
})

export const someQuery = extendType({
  type: 'Query',
  definition(t) {
    t.crud.some()
    t.crud.somes({ filtering: true, ordering: true })
  },
})

export const someMutation = extendType({
  type: 'Mutation',
  definition(t) {
    t.crud.createOneSome()
    t.crud.updateOneSome()
    t.crud.upsertOneSome()
    t.crud.deleteOneSome()

    t.crud.updateManySome()
    t.crud.deleteManySome()
  },
})

TypeError: Cannot read property 'includes' of undefined

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.

"convertSchema is not a function"

Updated to the latest "^1.2.1" and now when I run npx cnt -s -mq -f -o I get "convertSchema is not a function". This has been working up till this upgrade. Downgrading for now.

There are problems when compiling to JS

RUN cnt -s -mq -m -q -f -o --js

generate ok. But generated code Error.

export const User = objectType({
^^^^^^

SyntaxError: Unexpected token 'export'
...

Possible reasons ๏ผš

    fileContent += `export const ${model.name} = objectType({
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.