question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Attach comments to enum values

See original GitHub issue

Problem

/// user role
enum Role {
  ADMIN /// allowed to do everything
  USER
}

Comment allowed to do everything is not attached to the ADMIN value in the DMMF generator.

Generator DMMF output
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

datasource db {
  provider = "postgres"
  url      = env("POSTGRESQL_URL")
}

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

generator dbml {
  provider = "node ./dist/generator.js"
}

model User {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  email     String   @unique
  name      String?
  posts     Post[]
  profile   Profile?
  /// user role
  role      Role     @default(USER)
}

/// User profile
model Profile {
  id     Int     @default(autoincrement()) @id
  bio    String?
  user   User    @relation(fields: [userId], references: [id])
  userId Int     @unique
}

model Post {
  id         Int        @id @default(autoincrement())
  title      String     @default("")
  content    String?
  published  Boolean    @default(false)
  author     User?      @relation(fields: [authorId], references: [id])
  authorId   Int?
  categories Category[]
}

model Category {
  id    Int    @id @default(autoincrement())
  name  String
  posts Post[]
}

/// user role
enum Role {
  ADMIN /// allowed to do everything
  USER
}
{
  "enums": [
    {
      "name": "Role",
      "values": [
        { "name": "ADMIN", "dbName": null },
        { "name": "USER", "dbName": null }
      ],
      "dbName": null,
      "documentation": "user role"
    }
  ],
  "models": [
    {
      "name": "User",
      "isEmbedded": false,
      "dbName": null,
      "fields": [
        {
          "name": "id",
          "kind": "scalar",
          "isList": false,
          "isRequired": true,
          "isUnique": false,
          "isId": true,
          "isReadOnly": false,
          "type": "Int",
          "hasDefaultValue": true,
          "default": { "name": "autoincrement", "args": [] },
          "isGenerated": false,
          "isUpdatedAt": false
        },
        {
          "name": "createdAt",
          "kind": "scalar",
          "isList": false,
          "isRequired": true,
          "isUnique": false,
          "isId": false,
          "isReadOnly": false,
          "type": "DateTime",
          "hasDefaultValue": true,
          "default": { "name": "now", "args": [] },
          "isGenerated": false,
          "isUpdatedAt": false
        },
        {
          "name": "updatedAt",
          "kind": "scalar",
          "isList": false,
          "isRequired": true,
          "isUnique": false,
          "isId": false,
          "isReadOnly": false,
          "type": "DateTime",
          "hasDefaultValue": false,
          "isGenerated": false,
          "isUpdatedAt": true
        },
        {
          "name": "email",
          "kind": "scalar",
          "isList": false,
          "isRequired": true,
          "isUnique": true,
          "isId": false,
          "isReadOnly": false,
          "type": "String",
          "hasDefaultValue": false,
          "isGenerated": false,
          "isUpdatedAt": false
        },
        {
          "name": "name",
          "kind": "scalar",
          "isList": false,
          "isRequired": false,
          "isUnique": false,
          "isId": false,
          "isReadOnly": false,
          "type": "String",
          "hasDefaultValue": false,
          "isGenerated": false,
          "isUpdatedAt": false
        },
        {
          "name": "posts",
          "kind": "object",
          "isList": true,
          "isRequired": false,
          "isUnique": false,
          "isId": false,
          "isReadOnly": false,
          "type": "Post",
          "hasDefaultValue": false,
          "relationName": "PostToUser",
          "relationFromFields": [],
          "relationToFields": [],
          "relationOnDelete": "NONE",
          "isGenerated": false,
          "isUpdatedAt": false
        },
        {
          "name": "profile",
          "kind": "object",
          "isList": false,
          "isRequired": false,
          "isUnique": false,
          "isId": false,
          "isReadOnly": false,
          "type": "Profile",
          "hasDefaultValue": false,
          "relationName": "ProfileToUser",
          "relationFromFields": [],
          "relationToFields": [],
          "relationOnDelete": "NONE",
          "isGenerated": false,
          "isUpdatedAt": false
        },
        {
          "name": "role",
          "kind": "enum",
          "isList": false,
          "isRequired": true,
          "isUnique": false,
          "isId": false,
          "isReadOnly": false,
          "type": "Role",
          "hasDefaultValue": true,
          "default": "USER",
          "isGenerated": false,
          "isUpdatedAt": false,
          "documentation": "user role"
        }
      ],
      "isGenerated": false,
      "idFields": [],
      "uniqueFields": [],
      "uniqueIndexes": []
    },
   ...
  ]
}

Suggested solution

Attach comments to enum values

interface EnumValue {
   name: string;
   dbName: string;
+  documentation?: string;
}
interface DatamodelEnum {
  name: string;
  values: EnumValue[];
  dbName?: string | null;
  documentation?: string;
}

Alternatives

Additional context

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
SynergyEvolvedcommented, Sep 7, 2021

Hi There,

I am using prisma-nestjs-graphql generator and this is stopping the comments from the schema showing up in the generated registerEnumType.

https://github.com/unlight/prisma-nestjs-graphql/issues/43#issuecomment-904200469

1reaction
dieeisenefaustcommented, Jun 9, 2022

Issue #13726 has been opened for composite type comments.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How do I comment a publicly visible type Enum?
Yes I realize that comments are unnecessary, but if commenting is easy and it resolves the warnings then I'd like to do it....
Read more >
Attaching Values to Java Enum - Baeldung
Let's start by adding the element names. ... First of all, we notice the special syntax in the declaration list. This is how...
Read more >
Documenting Enum Values - MSDN - Microsoft
Hi,. Your commas are misplaced. The summaries below "Insert" are not applied to anything - they are just floating before a comma. Try ......
Read more >
PostGraphile | Enums
The @enum smart comments can be used to set the name ( @enumName ) or the ... a PostgreSQL enum, and you cannot...
Read more >
Language Guide (proto3) | Protocol Buffers - Google Developers
To add comments to your .proto files, use C/C++-style // and /* . ... For enums, the default value is the first defined...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found