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

Support for custom attributes #4002

Open
micahnz opened this issue Jun 30, 2019 · 13 comments
Open

Support for custom attributes #4002

micahnz opened this issue Jun 30, 2019 · 13 comments
Labels
domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. domain/psl Issue in the "PSL" domain: Prisma Schema Language kind/feature A request for a new feature. topic: dmmf topic: generator topic: schema

Comments

@micahnz
Copy link

micahnz commented Jun 30, 2019

I would like the ability to add custom attributes to the model that I could use to configure my generated API. For example I would like to define certain access control rights in the same file as I define the model rather than having a duplicate elsewhere. It would also come in handy to apply other API level modifiers where appropriate such as custom function calls before write or after read.

model Post {
  id        String   @default(cuid()) @id @unique
  createdAt DateTime @default(now()) @rbac.role('system')
  updatedAt DateTime @updatedAt @rbac.role('system')
  published Boolean @env('development') // only expose in development mode
  title     String @onRead("toUpperCase") @onWrite("toLowerCase")
  content   String?
  author    User? 
}

Currently I am reading schema information from the dmmf class and using it to generate my API, Ideally I would be able to call upon custom attributes at this point to shape the filters/abstraction rather than relying on an additional external config.

//
const photon = new Photon()
const { queryType, mutationType, modelMap } = photon.dmmf;

//
const Query = objectType({
  name: 'Query',
  definition(t) {
    forEach((f) => {
      if (typeof t.crud[f.name] === 'function') {
        // additional filters and abstraction here
        t.crud[f.name]();
      }
    }, queryType.fields);
  },
})
...

Currently I pull the information in separate from a config like so but it sure would be great if I could add the additional information in the same place as the model definitions some way.

---
Post:
 createdAt:
  rbac.role: system
 updateAt:
  rbac.role: system
 published:
  env: development
 title:
  onRead: toUpperCase
  onWrite: toLowerCase
@schickling
Copy link
Member

Thanks a lot for bringing this up. This is very interesting. I'd love to discuss this further. @michaelmitchell are you part of our Slack by any chance?

This is related to prisma/specs#7

@micahnz

This comment has been minimized.

@PinkaminaDianePie
Copy link

+1 for this :) I need to mark a field as embedded somehow, to read this info and process manually. It would be nice to be able to mark a field with any kind of attributes to be able to read it from the DMMF. It can be some "meta" field, where all non-standard attributes will go.

I'm playing a bit about using Prisma 2 with MongoDB, by replacing photon binaries with simple js file which just runs queries by using official Node.js driver, and I would like to know if I need to run a separate query to different collection or just take data as is, so having such kind of metadata would be useful for me. Maybe it's not a real use case, but I expect that people will build their own tools around Prisma 2, so such kind of metadata would be useful for them as well.

@albertoperdomo albertoperdomo transferred this issue from prisma/migrate Oct 22, 2020
@thdxr
Copy link

thdxr commented Dec 31, 2020

I would like custom attributes as well. I'm evaluating .prisma to be the way I define a source of truth for all things related to a schema but I need the ability to extend how I can decorate the attributes. All I need to happen is for them to not throw an error and show up in the DMMF

@Sytten
Copy link
Contributor

Sytten commented Dec 31, 2020

Yes I also support this as this is the base of a plugin system that could enable privacy filtering and other cool features.

@janpio janpio added the domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. label Mar 23, 2021
@Jolg42
Copy link
Contributor

Jolg42 commented Mar 25, 2021

@do4gr to validate if we error or ignore custom attributes. They are not surfaced in DMMF currently.

@chrisui
Copy link

chrisui commented Jul 1, 2021

Privacy and security features are important features which can be supported via extensions with custom attributes. Would be great to see this added.

@janpio janpio added domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. domain/psl Issue in the "PSL" domain: Prisma Schema Language topic: generator and removed domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. labels Sep 23, 2021
@bene
Copy link

bene commented May 30, 2022

Any updates on this? I really think this feature would enable so many possibilities to use the Prisma schema. Just imagine auto-generating GraphQL resolvers without worring to remove internal fields (e.g. passwords), just add a custom attribute like @graphql.omit.

@janpio
Copy link
Member

janpio commented Jun 13, 2022

Related: #1660

@jmarbutt
Copy link

jmarbutt commented Oct 7, 2022

This is also related to #3102 I put a comment that is very similar to what has been mentioned here.

@0xTK421
Copy link

0xTK421 commented Nov 1, 2022

I am also interested in this topic, it makes sense to me to keep application-specific attributes close to the model definition

@janpio
Copy link
Member

janpio commented Nov 2, 2022

Is there anything here in this issue not covered by #3102? Otherwise I think we should close this one and focus on #3102.

@martinratinaud
Copy link

Definitely need this also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. domain/psl Issue in the "PSL" domain: Prisma Schema Language kind/feature A request for a new feature. topic: dmmf topic: generator topic: schema
Projects
None yet
Development

No branches or pull requests