1.1.20 • Published 10 months ago

prisma-generator-basic-typegraphql v1.1.20

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

integration logo

prisma-generator-basic-typegraphql

This generator was bootstraped using create-prisma-generator

Description

An extremely basic typegraphql type generator for prisma. I needed something like typegraphql-prisma that works with prisma 4.0 and at that time, typegraphql-prisma had not updated their generator to support versioon 4.0, so I made this extremely simple generator to generate typegraphql types.

Essentially, this generator exports various folders and files into a desired directory with all models and enums converted to TypeGraphQL types which you can then use in your TypeGraphQL dependent project. This doesn't emit any CRUD operations like other generators. It just emits models and enums.

Installation

You can install this generator with:

yarn add --dev prisma-generator-basic-typegraphql

or

npm i -D prisma-generator-basic-typegraphql

or

pnpm add -D prisma-generator-basic-typegraphql

Usage

To use the generator, add the following to your schema.prisma file:

generator basic_typegraphql {
  provider        = "prisma-generator-basic-typegraphql"
  output          = "../generated/type-graphql-types"
  outputName      = "types.ts"
}

Config Options

The generator can be configured with the following options: | Option | Value | Default | Comment | | ----------------- |:---------------------------:|:---------------------------------------------------:|:-------------------------------------------------------------------------------------------------- | | output | string | ../src/generated/type-graphql-types | Folder where generated file will be stored. This folder is auto created if it doesn't exists. | | wipeOutput | boolean | false | If true, output folder will be deleted before new file is generated. | | strictModifiers | boolean | false | If true, all modifiers require to have '///' and be on top of field it modifies. | | installDeps | boolean | false | If true, dependencies based on schema will be installed like graphql-scalars. | | useYarn | boolean | false | Sets whether to use yarn or npm for installing packages if installDeps is true. | | hideRelations | boolean | false | By default, all fields without a modifier are emitted. If set to true, this will omit all relation types. | | skipVerCheck | boolean | false | If true, generator will run without checking installed prisma version. | | enumAsType | boolean | false | If true, generator will make all enums types. Generated enum as types will be named the same as their enum name and actual enums will also be emitted with _Enum attached at the end. | | enumAsConst | boolean | false | If true, generator will make all enums consts. Generated enum as consts will be named the same as their enum name. Actual enums won't be emitted, but types will also be emitted with their same enum names. | | optionalRelations | boolean | true | If true, generator will make all relation fields optional. | | addNull | boolean | false | If true, generator will add | null to TS type of optional fields. | | addUndefined | boolean | false | If true, generator will add | undefined to TS type of optional fields. | | addTypenameField | boolean | false | If true, generator will add a __typename field to all TS types. | | importAsESM | boolean | false | If true, all imports will be changed to work under ESM rules. |

Modifiers

If you want to modify a field, you can write a comment and add the modifiers above the field or after the field in the same line as the field. If the strictModifiers config option is set to true, then modifiers can only be typed above the field and must have ///, so wwe know it is a modifier and not a comment. Also, for every modifier type, I added various options so you can choose the one you like.

Modifiers: 1. Omit: To not include @Field to a field, meaning that the field is not exposed in graphql @omit @hide @TypeGraphQL.omit(output: true) 2. Emit: If hideRelation is true, then all relation types will be omitted. If you wan't some fields to be ignored by hideRelation, then use the emit modifier on desired fields to emit them. @emit @hide @TypeGraphQL.omit(output: false) 3. Nullable: If a field has been emitted, the nullable option in @Field will be set based on whether the field is required or not. If you want to override this, use this modifier. @nullable @null @TypeGraphQL.omit(nullable: true)

Notes

  1. Prisma's Unsupported type is not passed to the prisma generator, as in, in doess not get parsed at all, so I don't deal with that type in this generator.
  2. Since the relevant docs for creating a prisma generator are not easy to understand, I took inspiration from multiple generators, inlcuding create-prisma-generator, typegraphql-prisma and prisma-dbml-generator
  3. The image in this readme was sourced from typegraphql-prisma

1.1.19

10 months ago

1.1.20

10 months ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

2 years ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.13

1 year ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago