Skip to content

feat: support relation deprecation #2465

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

kartikaysaxena
Copy link
Contributor

@kartikaysaxena kartikaysaxena commented Jun 21, 2025

Related: #2396

This PR adds support for relation-level deprecation in schemas.

  • Relations can now be annotated with a @deprecated(...) directive to indicate they are deprecated.
  • When a relationship is written to a deprecated relation:
    • A warning or error is generated, depending on the specified deprecation level.
    • In the current implementation, writes fail when an error deprecation is configured.
  • Deprecation is associated with the immediately following relation in the definition.
  • A flag is to be passed to enable this feature, namely --enable-experimental-relationship-deprecation along with use directive.

Example:

use deprecation

definition user {}

definition resource {
  @deprecated(warn)
  relation viewer: user

  @deprecated(error)
  relation admin: user
}

Note

Each relation has an enum DeprecationType assigned to them, if unspecified it defaults to DEPRECATED_TYPE_UNSPECIFIED

@kartikaysaxena kartikaysaxena requested a review from a team as a code owner June 21, 2025 12:48
@github-actions github-actions bot added area/schema Affects the Schema Language area/api v1 Affects the v1 API area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Jun 21, 2025
Copy link

codecov bot commented Jun 21, 2025

Codecov Report

Attention: Patch coverage is 78.26087% with 30 lines in your changes missing coverage. Please review.

Project coverage is 77.39%. Comparing base (ce04edc) to head (2855726).

Files with missing lines Patch % Lines
internal/services/v1/relationships.go 70.00% 7 Missing and 2 partials ⚠️
pkg/schemadsl/parser/parser.go 66.67% 6 Missing and 3 partials ⚠️
pkg/schemadsl/compiler/translator.go 63.64% 6 Missing and 2 partials ⚠️
pkg/namespace/builder.go 83.34% 2 Missing and 1 partial ⚠️
pkg/cmd/testserver/testserver.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2465      +/-   ##
==========================================
- Coverage   77.39%   77.39%   -0.00%     
==========================================
  Files         416      416              
  Lines       50888    51023     +135     
==========================================
+ Hits        39381    39482     +101     
- Misses       9024     9048      +24     
- Partials     2483     2493      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kartikaysaxena kartikaysaxena force-pushed the support-relation-deprecation branch from 77f5d67 to cba3045 Compare June 25, 2025 11:58
Copy link
Contributor

@tstirrat15 tstirrat15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of comments.

I'm also wondering about the behavior of these annotations more generally - what happens if you put this annotation on a permission instead of a relation? Should it have an effect?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general note on the approach: to the degree that we can, we want to avoid breaking folks' existing schemas. See what we did with expiration for an example of how we've worked around it with use directives - if we add this feature, it'll be with one of those use directives.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need the composableschemadsl package to be updated accordingly.

Comment on lines 159 to 160
if l.acceptString("deprecated") {
l.emit(TokenTypeKeyword)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't something that should live in the lexer - it should live in the parser.

Or at least my sense is that an @ should be a marker, and then the token after it should be a keyword, rather than the entire thing being marked as a keyword.

It's also going to relate to what I said above about the use directive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be worth looking at #202, which implemented generic decorators (but we didn't have a use case so never merged it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reworked the approach a little bit including the use directive just like how it was done for expiration feature, adding more comments for better review.

@github-actions github-actions bot added the area/cli Affects the command line label Jun 27, 2025
@kartikaysaxena kartikaysaxena force-pushed the support-relation-deprecation branch from c9af820 to 4ad2bdc Compare June 27, 2025 19:25
@josephschorr
Copy link
Member

I wonder if we want to allow the deprecated annotation on each subject type vs the relation as a whole; I could see benefits to either. @ecordell thoughts?

@kartikaysaxena
Copy link
Contributor Author

we may also support something like

use deprecation

definition user {}

definition resource {
  relation viewer: user
  relation admin: user
}

@deprecated(warn, user, "<comments about deprecation>")
@deprecated(error, admin, "<comments about deprecation>")

which can include both subjects and relations, this way deprecation can be more flexible and granular also including the comments about the deprecation.

Any thoughts @josephschorr @ecordell @tstirrat15 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api v1 Affects the v1 API area/cli Affects the command line area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants