Cauen / prisma-generator-pothos-codegen

The fastest way to create a fully customizable CRUD Graphql API from Prisma Schema.
https://www.npmjs.com/package/prisma-generator-pothos-codegen
95 stars 16 forks source link

Enable support for "type" (composite types) in Prisma Schema (MongoDB) #26

Open Cauen opened 1 year ago

Cauen commented 1 year ago

On generation, the Address is not generated. https://www.prisma.io/docs/concepts/components/prisma-schema/data-model#defining-composite-types

The current workaround:

// configs.js
replacer: (str, section) => {
  if (section === 'crud.model.object') {
    return str.replace(
      "type: Inputs.Address,",
      'type: "Json", // Mongodb Types not working yet',
    );
  }
  return str;
},

Example schema with error

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

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

generator pothos {
  provider     = "prisma-pothos-types"
  // Match client output location from above
  clientOutput = "./client"
  output       = "./generated.d.ts"
}

generator pothosCrud {
  provider            = "prisma-generator-pothos-codegen"
  generatorConfigPath = "../src/schema/configs.js"
}

model Post {
  id       String    @id @default(auto()) @map("_id") @db.ObjectId
  slug     String    @unique
  title    String
  body     String
  Author   User      @relation(fields: [authorId], references: [id])
  authorId String    @db.ObjectId
}

model User {
  id      String   @id @default(auto()) @map("_id") @db.ObjectId
  email   String   @unique
  name    String?
  Address Address?
  Posts   Post[]
}

// Address is an embedded document
type Address {
  street String
  city   String
  state  String
  zip    String
}
m9rc1n commented 1 year ago

Hi guys, Great work on your generator!

What's your plan for this feature? Is https://github.com/hayes/pothos/issues/411 a blocker?

Cauen commented 1 year ago

Hi @m9rc1n, thanks Dont know exactly if it is a blocker

My plans are to proceed as soon as I have a little more free time. Any contributions are welcome \o/

m9rc1n commented 1 year ago

Thanks! Maybe next week I will also get some free time and can try to contribute.

2coo commented 1 year ago

Thanks for developing this plugin, it really helps us to create our MVP product much faster. Adding a feature that supports composite types would be really helpful.