Support for custom attributes
See original GitHub issueI 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:12 (5 by maintainers)
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 theDMMF
Is there anything here in this issue not covered by https://github.com/prisma/prisma/issues/3102? Otherwise I think we should close this one and focus on #3102.