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.

[schema] Hidden and read-only fields for models

See original GitHub issue

Problem

Some model attributes shall not be exposed at any time. For instance, createdAt may never be modified programmatically. Or id values shall not be returned from the public API.

Suggested solution

Read-only attributes could make sure not to expose fields like createdAt for modification:

model User {
  id String @id @default(cuid())
  createdAt DateTime @default(now()) @readonly
  // …
}

When querying for them, they would still be present in results, but they may not be updated.

Attributes like id may not be exposed by the results of find* and other methods, offering safer API results by default. However, hidden attributes like the id could still be used in conditions to cater for relations:

model User {
  id String @id @default(cuid()) @hidden
  // …
}

Alternatives

The naming of these @{rules} may be more explicit. Examples:

  • @access(read) / @access(condition)
  • @unselectable instead of @hidden

Also, hidden fields may be force-selected by specifying them in select objects.

Additional context

This issue is related to the discussion in #2127. While Nexus and other third-party solutions make it possible to constrain the usage of models, Prisma could make typing them way more convenient, especially for rest APIs.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
flybayercommented, Oct 18, 2020

Yes, we definitely need a @hidden feature!

Here’s a recent post by the Prisma team discussing @hidden: https://github.com/prisma/prisma-client-js/issues/649#issuecomment-700776231

And here’s a related issue on same problem: #3636

1reaction
flybayercommented, Oct 18, 2020

Oops, I fixed the reference. 3636 instead of 3936.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditional fields - Sanity.io
You can make fields in Sanity Studio's form appear and disappear using the hidden property, and make them read-only with the readOnly property ......
Read more >
ASP.NET MVC – HiddenInput and ReadOnly Attributes
HiddenInput attribute is useful when you want to render a property using input type=hidden . This attribute is extremely useful when you don't ......
Read more >
How can I hide fields in auto-generated schemas, or define ...
I thought that setting read_only and write_only attributes to True would hide fields from the documentation as they are omitted from request ...
Read more >
Part 43 Hiddeninput and readonly attributes in mvc - YouTube
HiddenInput attribute is useful when you want to render a property using input type= hidden. This attribute is extremely useful, ...
Read more >
Field element (Field) - SharePoint - Microsoft Learn
In addition, setting ReadOnly to TRUE hides the field from Site Settings pages for managing site columns and content types. Setting the Hidden...
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