Skip to content

feat: typechecking in schema#517

Merged
miparnisari merged 1 commit intomainfrom
typechecking
Feb 17, 2026
Merged

feat: typechecking in schema#517
miparnisari merged 1 commit intomainfrom
typechecking

Conversation

@miparnisari
Copy link
Contributor

No description provided.

@vercel
Copy link
Contributor

vercel bot commented Feb 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Feb 17, 2026 5:44pm

Request Review

Copy link
Collaborator

@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.

See comments

}
```

This will fail at `WriteSchema` time because the type annotation provided is incomplete; it should be `permission edit: user | serviceaccount = viewer & admin`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is weird. That silences the error but doesn't fix the semantic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

amended text

}
```

This schema compiles successfully, but a call to `CheckPermission` for `document#edit` will _always_ return false at runtime because the intersection of `user` and `serviceaccount` is empty. This is a bug that can go unnoticed for a long period of time, because the API call doesn't return an error.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"because no relationship can simultaneously be a user relationship and a serviceaccount relationship"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

It can be tempting to define the authorization logic for an endpoint as being the `AND` or `OR` of the checks of other permissions, especially when the alternative is writing a new schema.
However, this increases the likelihood of drift across your system, hides the authorization logic for a system in that system's codebase, and increases the load on SpiceDB.

### Use Typechecking
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be in the best practice list, but I think it should be a shorter description that references the documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be in the best practice list

WDYM? it is in the list already (see the name of the file)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right - for most other things that are documented elsewhere, the "you should" is a part of this doc, but the "what" and "how" are left to the linked documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, moved there!


### Typechecking

The `use typechecking` feature allows you to explicitly declare and validate the types that permissions can resolve to, providing compile-time type safety for your authorization schemas.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"compile-time" is technically true, but most folks aren't compiling their schemas, and I think this would lead folks to think that you needed to use zed schema compile to make use of this feature.

Comment on lines +487 to +488
permission view: user = viewer // Validated
permission edit = viewer // Not validated (no annotation)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that true? Are we not checking every permission?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This also seems like it contradicts the text in the best practices part of the documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we not checking every permission?

I just tried this in the playground and no, it doesn't enforce that every permission has the annotation, it only validates the annotations that exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also seems like it contradicts the text in the best practices part of the documentation

no, in that example, the annotation exists but it is incorrect

Comment on lines 516 to 517
relation viewer: user | team
permission view: user | team = viewer
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to have two separate relations, I think - otherwise this kinda reads as trivial.

Copy link
Collaborator

@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.

LGTM

@miparnisari miparnisari merged commit c761b65 into main Feb 17, 2026
20 of 21 checks passed
@miparnisari miparnisari deleted the typechecking branch February 17, 2026 17:48
@github-actions github-actions bot locked and limited conversation to collaborators Feb 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants