Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prisma-nestjs-graphql-resource-generator

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prisma-nestjs-graphql-resource-generator

Generates crud resources (resolver,service,module,test-files) for a prisma, nestjs, graphql setup

  • 0.1.0
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by800%
Maintainers
1
Weekly downloads
 
Created
Source

prisma-nestjs-graphql-resource-generator

Generates crud resources (resolver,service,module,test-files) for a prisma, nestjs, graphql setup

Goal of the npm package (p):

  • Working with prisma, nestjs and graphql is a great thing (imo).
  • Nest.js resource generation is somewhat inefficient if you use types generated by prisma-nestjs-graphql (https://github.com/unlight/prisma-nestjs-graphql).
  • This p (should be) able to auto-generate crud resolvers for your models defined in prisma.schema.
  • Second, the p should register the new crud models in a module file that has to be provided by you.

How to use the p:

  • Install it: npm i -D prisma-nestjs-graphql-resource-generator
  • It needs you to also use https://www.npmjs.com/package/prisma-json-schema-generator as generator for your prisma setup.
  • The p will look for a file called prisma/generated/json-schema.json which should be generated by the prisma-json-schema-generator
  • Therefore the generator should look somewhat like that:
...
generator jsonSchema {
  provider = "prisma-json-schema-generator"
  output   = "./generated/"
}
...
  • After npx prisma generate you should decide on a folder you want to place the resource-files in, i will call mine models
  • Inside this folder a models.module.ts file has to be created including somewhat like:
import { Module } from '@nestjs/common';

@Module({
  imports: [],
  exports: [],
})
export class ModelsModule {}

  • Execute
    • npx gm models/person to generate only one resource, here the person resource
    • npx gmall to generate all prisma models that haven't been generated yet. Here the folder must be named models and the folder must be a direct subfolder of src.
  • The result should look like:
src
|
|-models <== creation of this one is in your responsibility
  |
  |- models.module.ts <== creation of this one is in your responsibility, it's name must be "models.module.ts"
  |
  |- person <== first generated crud resource folder
     |
     |- person.module.ts
     |- person.resolver.spec.ts
     |- person.resolver.ts
     |- person.service.spec.ts
     |- person.service.ts
     |
  |- address <== second generated crud resource folder
     |
     |- address.module.ts
     |- address.resolver.spec.ts
     |- address.resolver.ts
     |- address.service.spec.ts
     |- address.service.ts
     |

 ...

Known issues:

  • Imports are added automatically (and naively) => if an import in a resolver file already exists before linting and the same one gets added by the linter => it will exist twice => error
    • Just delete the second (generated) import.
  • file names and source file paths are rigid and cannot be configured (atm)

FAQs

Package last updated on 20 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc