Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triple-slash Comments should attach to Composite Types #13726

Closed
Tracked by #18561
dieeisenefaust opened this issue Jun 9, 2022 · 10 comments · Fixed by prisma/prisma-engines#4034
Closed
Tracked by #18561

Triple-slash Comments should attach to Composite Types #13726

dieeisenefaust opened this issue Jun 9, 2022 · 10 comments · Fixed by prisma/prisma-engines#4034
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: client types Types in Prisma Client topic: comments topic: composite-types topic: dmmf
Milestone

Comments

@dieeisenefaust
Copy link

dieeisenefaust commented Jun 9, 2022

Bug description

Currently, triple-slash comments ("///") only appear to attach to actual model types.

They should also attached to composite types.

How to reproduce

  1. Create a composite type entry in your schema.prisma
  2. Run 'npx prisma generate'
  3. Check the generated TS types

Example:L
(note, I am trying to use the nestjs-prisma-graphql package to apply validators, which is dependent on the comments functionality and so also fails to generate the validator decorators in the TS input types. But at the most basic - not involving any other packages, the basic comment I applied to the 'name' doesn't come over)

image

image

Expected behavior

Expect the comments on composite types to be included in the generated TS types.

Example of it working on a regular model entry:
image

image

(here you can see the nestjs-prisma-graphql package is able to pick up the decorators in the comments and apply them)
image

Prisma information

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

generator nestgraphql {
  provider = "node node_modules/prisma-nestjs-graphql"
  output   = "../src/@generated"

  fields_Validator_from  = "class-validator"
  fields_Validator_input = true
}

// generator typegraphql {
//   provider = "typegraphql-prisma"
//   output   = "../prisma/generated/type-graphql"
// }

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

model User {
  ///This is a test of comments on models
  ///@HideField({input: true})
  id              String       @id @default(auto()) @map("_id") @db.ObjectId
  ///@Validator.IsEmail()
  email           String       @unique
  firstName       String?
  lastName        String?
  username        String       @unique
  password        String?
  //@Validator.MinDate(new Date(1930, 0, 1))
  birthday        String?
  shippingAddress Address?
  creditCards     CreditCard[]
  punchCards      PunchCard[]
}

type Address {
  street     String
  postalCode String
  city       String
  state      String
}

type CreditCard {
  ///This is a test of comments on composite types
  name            String
  cardNumber      String
  ///@Validator.Min(1)
  ///@Validator.Max(12)
  expirationMonth Int
  ///@Validator.Min(2015)
  ///@Validator.Max(3000)
  expirationYear  Int
  code            Int
  billingAddress  Address
}

model Event {
  id                   String               @id @default(auto()) @map("_id") @db.ObjectId
  eventType            EventType
  location             Address
  startDate            String
  endDate              String
  hoo                  HoursOfOperation
  participants         Participant[]        @relation(fields: [participantId], references: [id])
  participantId        String[]             @db.ObjectId
  participantProducts  ParticipantProduct[] @relation(fields: [participantProductId], references: [id])
  participantProductId String[]             @db.ObjectId
  punchCards           PunchCard[]
}

model Participant {
  id       String               @id @default(auto()) @map("_id") @db.ObjectId
  name     String
  products ParticipantProduct[]
  events   Event[]              @relation(fields: [eventId], references: [id])
  eventId  String[]             @db.ObjectId
}

model ParticipantProduct {
  id            String      @id @default(auto()) @map("_id") @db.ObjectId
  name          String
  description   String
  participant   Participant @relation(fields: [participantId], references: [id])
  participantId String      @db.ObjectId
  events        Event[]     @relation(fields: [eventId], references: [id])
  eventId       String[]    @db.ObjectId
  PunchBox      PunchBox[]
}

type HoursOfOperation {
  date      String
  startTime String
  endtime   String
}

enum EventType {
  BEERFEST
  WINEFEST
  CARNIVAL
  CIDERFEST
}

model PunchCard {
  ///@hidden()
  id      String @id @default(auto()) @map("_id") @db.ObjectId
  event   Event  @relation(fields: [eventId], references: [id])
  eventId String @db.ObjectId
  user    User   @relation(fields: [userId], references: [id])
  userId  String @db.ObjectId
}

model PunchBox {
  id                  String              @id @default(auto()) @map("_id") @db.ObjectId
  used                Boolean             @default(false)
  product             ParticipantProduct? @relation(fields: [particpandProductId], references: [id])
  particpandProductId String?             @db.ObjectId
}

Environment & setup

  • OS: Windows 10
  • Database: MongoDB (Atlas)
  • Node.js version: 18.2.0

Prisma Version

prisma                  : 3.15.0
@prisma/client          : 3.15.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine b9297dc3a59307060c1c39d7e4f5765066f38372 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli b9297dc3a59307060c1c39d7e4f5765066f38372 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core b9297dc3a59307060c1c39d7e4f5765066f38372 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt b9297dc3a59307060c1c39d7e4f5765066f38372 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : b9297dc3a59307060c1c39d7e4f5765066f38372
Studio                  : 0.462.0
@dieeisenefaust dieeisenefaust added the kind/bug A reported bug. label Jun 9, 2022
@jkomyno jkomyno added kind/improvement An improvement to existing feature and code. team/client Issue for team Client. and removed kind/bug A reported bug. labels Jun 13, 2022
@Brakebein
Copy link

I'm also generating DTOs from the prisma schema and decorating the properties with class-validators etc. With the /// documentation above a field, I can control which decorators should be applied. This works quite well with the standard model.

Now, I'm extending my generator for composite types type, but just found out that the documentation of a field is not getting parsed. So, I'm also interested in this feature.

@janpio janpio added topic: composite-types bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. and removed kind/improvement An improvement to existing feature and code. labels Aug 8, 2022
@janpio
Copy link
Member

janpio commented Aug 8, 2022

Thanks for that information bit, seems my colleague missed the details that this works different for type than for model - which makes this a bug we should fix. Thanks!

@garrensmith garrensmith changed the title Tiple-slash Comments should attach to Composite Types Triple-slash Comments should attach to Composite Types Aug 23, 2022
@arthurfiorette
Copy link
Contributor

Hello @janpio, any updates on this bug?

@janpio
Copy link
Member

janpio commented Jan 6, 2023

No, there is no confirmed reproduction and the issue only gets minimal upvotes/👍 so this is low in our priority list. We'll get to it some time, but not sure when.

@michaelpoellath
Copy link

@janpio We encounter the same issue, DMMF does not expose documentation for composite types. We plan to use prisma + generators for GraphQL types and this is kind of blocking because of missing documentation in the resulting schema. Is there any progress on the Ticket?
If not i gladly pick it up and contribute a fix, just need a pointer where to look.

@janpio
Copy link
Member

janpio commented Feb 1, 2023

@michaelpoellath A project that makes it easy to confirm that these values are missing would help as a first step. Maybe something that outputs the dmmf, and shows how some comments are attached and some are not. When we have the confirmation, we can either prioritize this or help you figure out where things might be going wrong. (This is certainly in our Rust codebase at prisma-engines.)

@michaelpoellath
Copy link

Sorry for the late update @janpio!

I just created a demo repo (https://github.com/michaelpoellath/prisma-13726) which shows that docs on type are missing.
Hope this helps to confirm the issue.

@janpio janpio added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jun 8, 2023
@janpio
Copy link
Member

janpio commented Jun 8, 2023

Thank you!

To persist:

///  A Person
model person {
  /// Id
  id String @id @map("_id")
  /// Name of  the Person
  name name
}

/// A Name
type name {
  /// First Name
  firstname String
  /// Last Name
  lastname String
}

leads to:

==== Print Documentation on MODELS:
prisma:info MODEL "person" -- docs: "A Person"
prisma:info FIELD "id" -- docs: "Id"
prisma:info FIELD "name" -- docs: "Name of  the Person"
prisma:info 

==== Print Documentation on TYPES:
prisma:info TYPE "name" -- docs: "undefined"
prisma:info FIELD "firstname" -- docs: "undefined"
prisma:info FIELD "lastname" -- docs: "undefined"

because of this DMMF datamodel for the generator (options.dmmf.datamodel):

 {
  "enums": [],
  "models": [
    {
      "name": "person",
      "dbName": null,
      "fields": [
        {
          "name": "id",
          "dbName": "_id",
          "kind": "scalar",
          "isList": false,
          "isRequired": true,
          "isUnique": false,
          "isId": true,
          "isReadOnly": false,
          "hasDefaultValue": false,
          "type": "String",
          "isGenerated": false,
          "isUpdatedAt": false,
          "documentation": "Id"
        },
        {
          "name": "name",
          "kind": "object",
          "isList": false,
          "isRequired": true,
          "isUnique": false,
          "isId": false,
          "isReadOnly": false,
          "hasDefaultValue": false,
          "type": "name",
          "isGenerated": false,
          "isUpdatedAt": false,
          "documentation": "Name of  the Person"
        }
      ],
      "primaryKey": null,
      "uniqueFields": [],
      "uniqueIndexes": [],
      "isGenerated": false,
      "documentation": "A Person"
    }
  ],
  "types": [
    {
      "name": "name",
      "dbName": null,
      "fields": [
        {
          "name": "firstname",
          "kind": "scalar",
          "isList": false,
          "isRequired": true,
          "isUnique": false,
          "isId": false,
          "isReadOnly": false,
          "hasDefaultValue": false,
          "type": "String"
        },
        {
          "name": "lastname",
          "kind": "scalar",
          "isList": false,
          "isRequired": true,
          "isUnique": false,
          "isId": false,
          "isReadOnly": false,
          "hasDefaultValue": false,
          "type": "String"
        }
      ],
      "primaryKey": null,
      "uniqueFields": [],
      "uniqueIndexes": []
    }
  ]
}

@janpio
Copy link
Member

janpio commented Jun 8, 2023

Related issue: #17828 (but for enums)

@janpio janpio added topic: comments topic: client types Types in Prisma Client labels Jun 8, 2023
@michaelpoellath
Copy link

Found the issue and preparing a fix. Will update here with a link later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: client types Types in Prisma Client topic: comments topic: composite-types topic: dmmf
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants