This package has been deprecated

Author message:

This CLI is moved under @paljs/cli => pal g command https://paljs.com/cli/cnt

create-nexus-type

1.3.0 • Public • Published

Create nexus type?

This is Cli tool to Create nexus type for Prisma projects. When you try to upgrade from Prisma 1 to Prisma 2 and need to write nexus types for your models this tool will create this types for you from your schema.prisma file

How use?

yarn add -D create-nexus-type
or
npm i create-nexus-type --save-dev

Command options for cnt

  --schema To add schema file path if you not run command in root of project
  --outDir Created files output dir default src/types
  -s       add this option to use @nexus/schema package
  -mq      add this option to create Queries and Mutations for models
  -m       add this option to create Mutations
  -q       add this option to create Queries
  -c       add this option to create Queries Count
  -f       add this option to add {filtering: true} option to Queries
  -o       add this option to add {ordering: true} option to Queries
  --js     create javascript version
  --mjs    create es modules version

Example

// schema.prisma
 
datasource postgresql {
  url      = env("DATABASE_URL")
  provider = "postgresql"
}
 
generator client {
  provider = "prisma-client-js"
}
 
model User {
  id        String   @id @default(cuid())
  email     String   @unique
  birthDate DateTime
  posts     Post[]
}
 
model Post {
  id     String @id @default(cuid())
  author User[]
}

Run

npx cnt --mq -c -f -o

OutPut

import { objectType, extendType } from "@nexus/schema";
 
export const User = objectType({
  name: "User",
  definition(t) {
    t.model.id();
    t.model.email();
    t.model.birthDate();
    t.model.posts();
  },
});
 
export const userQuery = extendType({
  type: "Query",
  definition(t) {
    t.crud.user();
    t.crud.users({ filtering: true, ordering: true });
 
    t.field("usersCount", {
      type: "Int",
      args: {
        where: "UserWhereInput",
      },
      async resolve(_root, args, ctx) {
        return ctx.prisma.user.count(args);
      },
    });
  },
});
 
export const userMutation = extendType({
  type: "Mutation",
  definition(t) {
    t.crud.createOneUser();
    t.crud.updateOneUser();
    t.crud.upsertOneUser();
    t.crud.deleteOneUser();
 
    t.crud.updateManyUser();
    t.crud.deleteManyUser();
  },
});

Create TypeScript types

Have another option to create TypeScript types to use for your work

Command options for create-types

  usage: create-types (Create TypeScript types from Prisma schema)
  --schema To add schema file path if you not run command in root of project
  --outDir Created files output dir default src/generated

Example

// schema.prisma
 
datasource postgresql {
  url      = env("DATABASE_URL")
  provider = "postgresql"
}
 
generator client {
  provider = "prisma-client-js"
}
 
model User {
  id        String   @id @default(cuid())
  email     String   @unique
  birthDate DateTime?
  role      UserRole
  posts     Post[]
}
 
model Post {
  id     String @id @default(cuid())
  author User[]
}
 
enum UserRole {
  USER
  ADMIN
}

run

npx create-types

OutPut

// types.ts
export interface User {
  id: string;
  email: string;
  birthDate: Date | null;
  role: UserRole;
  posts: Post[];
}
 
export interface Post {
  id: string;
  author: User[];
}
 
enum UserRole {
  USER = "USER",
  ADMIN = "ADMIN",
}

Have questions?

Didn't find something here? Look through the issues or simply drop us a line at ahmed.elywa@icloud.com.

Like my tool give me star

Readme

Keywords

none

Package Sidebar

Install

npm i create-nexus-type

Weekly Downloads

221

Version

1.3.0

License

MIT

Unpacked Size

11.4 kB

Total Files

6

Last publish

Collaborators

  • ahmedelywa