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.

Support for custom attributes

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:12
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
thdxrcommented, 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

0reactions
janpiocommented, Nov 2, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create custom attributes for user profiles - Google Support
Click User information. Click any of the custom attribute sections to edit it. Add or change values to custom attributes. Click Save.
Read more >
CSS Variables (Custom Properties) | Can I use... Support ...
CSS Variables (Custom Properties). - CR. Permits the declaration and usage of cascading variables in stylesheets. Usage % of. all users, all tracked ......
Read more >
Create and Manage Custom Attributes | Square Support Center
Go to the online Square Dashboard. · Navigate to the item library. · Select Custom Attributes. · Click the Create a custom attribute...
Read more >
Custom Attributes - Braze
Custom attributes are a collection of your users' unique traits. Custom attributes are best for storing attributes about your users, or information about ......
Read more >
Custom Attributes - IBM
Custom attributes, also known as user-defined attributes, are defined on business objects. In web services, each web service object that supports custom ...
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