Code Monkey home page Code Monkey logo

nestjs-prisma-graphql-crud-gen's Introduction

icon

NestJS Prisma GraphQL CRUD Generater

Generate CRUD resolvers from GraphQL schema with NestJS and Prisma

Getting Started

  1. Install this package in your project using:
yarn add nestjs-prisma-graphql-crud-gen
  1. Add the generator to the schema.prisma:
generator custom_generator {
  provider = "nestjs-prisma-graphql-crud-gen"
  output = "../generated"
}
  1. Run the generator
npx prisma generate

Output Directory Structure

generated/
├── common
│   ├── enums.ts
│   └── inputs.ts
├── models
│   └── users.models.ts
└── users
    ├── users.args.ts
    ├── users.enum.ts
    ├── users.input.ts
    ├── users.module.ts
    ├── users.output.ts
    ├── users.resolver.ts
    └── users.service.ts

Sample results here

Sample Project

nestjs-graphql-starter

nestjs-prisma-graphql-crud-gen's People

Contributors

dependabot[bot] avatar minjunghyun avatar mk668a 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

Watchers

 avatar  avatar  avatar

nestjs-prisma-graphql-crud-gen's Issues

Path issue in .args.ts files for imports

I have 3 tables im my DB:

user
role
user_roles

The models are User, Role and UserRoles

After generation folder with files in the user.args.ts file I have errors connected with import paths. Each time when I generating and getting new graphql schema I mannualy changing the paths. For example:

import { UserRolesWhereInput } from '../user/inputs/UserRolesWhereInput.input';

to

import { UserRolesWhereInput } from '../userRoles/inputs/UserRolesWhereInput.input';

In user.args.ts file.

How can I solve this issue and, also, how can I generate new table CRUDs for each generations only? I don't want to generate every time from scratch for each tables.

@mk668a @MinJungHyun When you can fix this issue?

enum path error

  1. add code schema.prisma
  2. start:dev
  3. enum path error
model Place {
  id   Int    @id @default(autoincrement())
  name String

  stamps Stamp[]
}

model Stamp {
  id       Int      @id @default(autoincrement())
  count    String
  mealType MealType @default(breakfast)

  place   Place? @relation(fields: [placeId], references: [id])
  placeId Int?
}

enum MealType {
  breakfast
  lunch
  dinner
  night
}

CreateMany in args

CreateMany[Model]Args is not generated in [Model]/[Model].args.ts but is used both in [Model].service.ts and [Model].resolver.ts. Is there any way to customize the templates?

There are issues in outputs

After this commit 2e4ff13 (or latest commits) there are issues in outputs. 2 files not genereated and for the following files there are imports issues.

  1. {modelName}/output/Aggregate{modelName}.output.ts
  2. {modelName}/output/{modelName}GroupBy.output.ts

import { {modelName}AvgAggregate } from '../../common/outputs/{modelName}AvgAggregate.output';
import { {modelName}SumAggregate } from '../../common/outputs/{modelName}SumAggregate.output';

@mk668a @MinJungHyun When you can fix this issue?

Config PrismaServiceFilePath

Hi, awesome work with this generator makes nestjs and Prisma dev seamless.

Could you add an option to the generator options to enable picking a custom path for the prisma.service file i.e.
generator nestjs_graphql_crud_gen {
// . . .
prismaServiceFilePath = "<custom-path-to-prisma.service>"
}

Cannot access 'NestedIntFilter' before initialization

I followed all the step showed on README, but when I run the application, I'm getting this error

/workspaces/nest-demo/src/generated/common/inputs.ts:28
not?: NestedIntFilter | undefined;
^
ReferenceError: Cannot access 'NestedIntFilter' before initialization
at Object. (/workspaces/nest-demo/src/generated/common/inputs.ts:28:9)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (/workspaces/nest-demo/src/generated/article/inputs/ArticleScalarWhereWithAggregatesInput.input.ts:2:1)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)

can you add a semicolon?

image

generateModule, generateEnum, generateCommonEnums, generateService, generateResolver.....

thank you

generator stucks without error and no generation

hey,

all my depenencies (prisma, nestjs,...) are at @latest , node is latest lts

in my console:

root@a3b11efbd3a4:/api# npx prisma generate
Environment variables loaded from prisma/.env
Prisma schema loaded from prisma/schema.prisma
prisma:info nestjs-prisma-graphql-crud-gen:Registered
// NOTHING HAPPENS, it just stucks and  nothing is generated from the crud gen

my schema.prisma config


generator client {
  provider = "prisma-client-js"
}

generator nestgraphql {
    provider = "node node_modules/prisma-nestjs-graphql"
    output = "../src/@generated/dto"
    noAtomicOperations = true
    fields_Validator_from = "class-validator"
    fields_Validator_input = true
}

generator crudgenerator {
  provider = "node node_modules/nestjs-prisma-graphql-crud-gen"
  output = "../src/@generated/crud"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

what i have tryed, but didn't work either, write config like in the official example
this:

generator custom_generator {
  provider = "nestjs-prisma-graphql-crud-gen"
  output = "../src/generated"
}

I also diabled the nestgraphql called generator, but no change
Any options to get a debug/log ?

Hide sensitive fields from GraphQL models and responses

Hi @mk668a

Awesome work with this generator package.

Would it be possible to allow users to mark some fields as "hidden" from the generated GraphQL models/ outputs e.g hide password on User model?

I'd be happy to help work on this if you have any ideas.

Cheers

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.