npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@appsynergica/graphqlizer

v0.0.12

Published

A Command Line App for adding “code first” nestjs graphql decorators and or class validator decorators to TypeORM entities.

Downloads

3

Readme

Graphqlizer

GitHub stars GitHub forks GitHub watchers GitHub followers

A Command Line App for adding "code first" nestjs graphql decorators and or class validator decorators to TypeORM entities.

Installation

npm i @appsynergica/graphqlizer -D

Usage

#with custom path for graphqlizer.json :
graphqlizer -P "path/to/graphqlizer.json"
#with graphqlizer.json located in root folder:
graphqlizer

Example # 1 : Basic Usage

The following example adds both graphql and class validator decorators to typeorm entities thereby transforming them into code first nestjs graphql object types. Since the source files and output files are the same, it will simply appear as though the respective decorators have been added to the respective typeorm entities.

Note : it is advisable to backup entities before performing this example incase the output turns out not to be satisfactory

Steps : 3 Only

  • Step #1: Add a graphqlizer.json file in the root folder of your project.
  • Step #2: Add the following JSON Object to graphqlizer.json : Note: Don't forget step #3 (after the json object shown below)

{  
    "globalOptions": {  
        "sourceFilePathGlob": "src/core/database/entities/*.ts",  
  "outputRootPath": "src",  
  "isToSingleQuotes": false,  
  "fileNameType": "t",  
  "indentationText": "two",  
  "lineFeedKind": "n",  
  "isToUseTrailingCommas": false,  
  "isToUsePrefixAndSuffixTextForRename": false  
  },  
  "outputClasses" : [  
        {  
            "className": "{{sourceClassName}}",  
  "graphqlObjectType": "o",  
  "filePath": "{{outputRootPath}}/core/database/entities/{{sourceClassName}}.ts",  
  "isEverythingOptional": false,  
  "isToAddClassValidatorDecorators": true,  
  "isToAddNestJSGraphQLDecorators": true,  
  "isToAddTypeOrmDecorators": true  
  }  
  
    ]  
}
  • Step #3: Add an npm script in package.json to call the graphqlizer or simply execute the following command in a command prompt :
#with custom path for graphqlizer.json :
graphqlizer -P "path/to/graphqlizer.json"

OR

#with graphqlizer.json located in root folder:
graphqlizer

Example # 2 : Advanced Usage

The following example generates the following entities.

  • Typeorm entities with class validator entities and nestjs code first entities. These entities will overwrite the source file
  • entities without any decorators. These entities may be necessary for browser side apps as typeorm decorators are offensive to webpack. These entities will be placed in the file path : "src/core/browser/entities/*.ts"
  • Multiple nestjs code first input type entities in the same file. These entities will have class validator decorators and nestjs code first decorators but no typeorm entities. These entities will all be placed in the same file: "src/core/graphql/input/*.ts".

Note : it is advisable to backup entities before performing this example incase the output turns out not to be satisfactory

Steps : 3 Only

  • Step #1: Add a graphqlizer.json file in the root folder of your project.
  • Step #2: Add the following JSON object to the graphqlizer.json file : Note: Don't forget step #3 (after the json object shown below)

{  
    "globalOptions": {  
        "sourceFilePathGlob": "src/core/database/entities/*.ts",  
  "outputRootPath": "src",  
  "isToSingleQuotes": false,  
  "fileNameType": "t",  
  "indentationText": "two",  
  "lineFeedKind": "n",  
  "isToUseTrailingCommas": false,  
  "isToUsePrefixAndSuffixTextForRename": false  
  },  
  "outputClasses" : [  
        {  
            "className": "{{sourceClassName}}",  
  "graphqlObjectType": "o",  
  "filePath": "{{outputRootPath}}/core/database/entities/{{sourceClassName}}.ts",  
  "isEverythingOptional": false,  
  "isToAddClassValidatorDecorators": true,  
  "isToAddNestJSGraphQLDecorators": true,  
  "isToAddTypeOrmDecorators": true  
  },
{
            "className": "{{sourceClassName}}",
            "graphqlObjectType": "o",
            "filePath": "{{outputRootPath}}/core/browser/entities/{{sourceClassName}}.ts",
            "isEverythingOptional": false,
            "isToAddClassValidatorDecorators": false,
            "isToAddNestJSGraphQLDecorators": false,
            "isToAddTypeOrmDecorators": false
        },
        {
            "className": "{{sourceClassName}}SearchOptions",
            "graphqlObjectType": "i",
            "filePath": "{{outputRootPath}}/core/graphql/input/{{sourceClassName}}.input.ts",
            "isEverythingOptional": true,
            "isToAddClassValidatorDecorators": true,
            "isToAddNestJSGraphQLDecorators": true,
            "isToAddTypeOrmDecorators": false,
            "hasNoProperties": true
        },
        {
            "className": "Add{{sourceClassName}}Input",
            "graphqlObjectType": "i",
            "filePath": "{{outputRootPath}}/core/graphql/input/{{sourceClassName}}.input.ts",
            "isEverythingOptional": false,
            "isToAddClassValidatorDecorators": true,
            "isToAddNestJSGraphQLDecorators": true,
            "isToAddTypeOrmDecorators": false
        },
        {
            "className": "Update{{sourceClassName}}Input",
            "graphqlObjectType": "i",
            "filePath": "{{outputRootPath}}/core/graphql/input/{{sourceClassName}}.input.ts",
            "isEverythingOptional": true,
            "isToAddClassValidatorDecorators": true,
            "isToAddNestJSGraphQLDecorators": true,
            "isToAddTypeOrmDecorators": false
        }  
  
    ]  
}
  • Step #3: Add an npm script in package.json to call the graphqlizer or simply execute the following command in a command prompt :
#with custom path for graphqlizer.json :
graphqlizer -P "path/to/graphqlizer.json"

OR

#with graphqlizer.json located in root folder:
graphqlizer

Detailed Overview

Add a graphqlizer.json file in the root folder of your project. The file should contain a JSON Object with the following properties

#globalOptions A JSON Object with the following properties

  • "sourceFilePathGlob" : A glob path containing the source files
  • "outputRootPath": The root file path to place all output
  • "isToSingleQuotes": A boolean for whether to use single quotes or double quotes (Recommended : use double quotes)
  • "fileNameType": A string for the file name type : "k" for kebarb case "c" for camel case "t" for type case
  • "indentationText": A string for the indentation level either "two", "four" or "eight"
  • "lineFeedKind": A string for the line feed "n" for new line, "c" for carriage return,
    "isToUseTrailingCommas": false,
    "isToUsePrefixAndSuffixTextForRename": false

Output classes

A JSON Array of entity generation options. The array can be used to generate multiple graphql entity types such as input types, output types and object types. The array can even be used to specify options that can remove decorators from typeorm entities.

Note : Entity generation options with the same output file name will result in multiple classes being placed in the same file.

Entity Generation Option

A JSON Object specifying output generation options

  • "className": The name of the class to be generated. The class name can be generated using the following mustache variables:
    • {{sourceClassName}} : resolves to the current source entity being tranformed
  • "graphqlObjectType": The nestjs Graphql type to create "o" for object type, "i" for input type,
  • "filePath": The output file path. The path can be generated using the following mustache variables :
    • {{outputRootPath}} : resolves to the rootpath property of the globalOptions object
    • {{sourceClassName}} : resolves to the current source entity being tranformed e.g of an output path : {{outputRootPath}}/core/database/entities/{{sourceClassName}}.ts",
    • "isEverythingOptional": A boolean for whether to make all fields optional,
  • "isToAddClassValidatorDecorators": A boolean for whether to add class validator options or not,
  • "isToAddNestJSGraphQLDecorators": A boolean of whether to add nestjs graphql decorators or not,
    -"isToAddTypeOrmDecorators": A boolean of whether to add typeorm decorators or not -"isToUsePrimitiveScalarForID" : A boolean of whether to use String or Int as the Graphql Scalar type instead of ID. This option is only applicable when the "isToAddNestJSGraphQLDecorators" option is set to true. Note: "isToUsePrimitiveScalarForID" is an optional key in the Entity Generation Option json object.