Repository navigation
feat: conditional relationships evaluate readable/writable guards per-request - #450
Merged
Merged
Conversation
jkeen
reviewed
Feb 27, 2024
| end | ||
|
|
||
| context "when a sideload macro not readable" do | ||
| xcontext "when a sideload macro not readable" do |
jkeen
added a commit
that referenced
this pull request
Jul 29, 2026
…ditional relationships) (#450) Symbols, strings, and procs passed to a relationship's readable/writable options are now evaluated per-request instead of being silently truthy. Unreadable relationships are omitted from serialization and scrubbed from includes; unwritable ones reject sideposting with unwritable_relationship. The declaring resource wins when the guard exists on both sides. Because these guards were previously ignored, upgrading apps get three signals: guarded relationships are marked in schema.json and SchemaDiff reports them as 'became guarded', a post_install_message warns on bundle update, and Graphiti.guarded_relationships lists every affected relationship for auditing. Also fixes serializer relationship_condition_blocks leaking across the serializer hierarchy via shared class_attribute state, and a spec-suite Graphiti.logger double leak.
Moves readable/writable check to serializer so that the check happens before each render vs once on load.
Relationship readable/writable guards set with a symbol or proc just read as true before this change. Enforcing them changes behavior for any app that declared one, so two upgrade signals: - schema.json now marks guarded relationships, and SchemaDiff reports "became guarded" as backwards-incompatible, naming each one in CI. - A gemspec post_install_message points everyone else at the new Graphiti.guarded_relationships audit helper at bundle update.
jkeen
force-pushed
the
fix-conditional-realtionships
branch
from
July 29, 2026 02:41
306259d to
d409463
Compare
github-actions Bot
pushed a commit
that referenced
this pull request
Jul 29, 2026
# [1.12.0](v1.11.1...v1.12.0) (2026-07-29) ### Bug Fixes * GQL name chaining ([#415](#415)) [skip ci] ([930928a](930928a)) ### Features * conditional relationships evaluate readable/writable guards per-request ([#450](#450)) ([3ed3187](3ed3187)) * pass the model and attribute name to writable guards ([#511](#511)) [skip ci] ([24a8a94](24a8a94))
Contributor
|
🎉 This PR is included in version 1.12.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
jkeen
added a commit
to jkeen/graphiti
that referenced
this pull request
Jul 30, 2026
…-request (graphiti-api#450) Symbols, strings, and procs passed to a relationship's readable/writable options are now evaluated per-request instead of being silently treated as true. Unreadable relationships are omitted from serialization and scrubbed from includes; unwritable ones reject sideposting with an unwritable_relationship error. The resource declaring the relationship wins when the guard is defined on both sides; guards take no arguments because include scrubbing runs before any records exist. apps already passing non-boolean values to these options gain enforcement on upgrade. Guarded relationships are marked in schema.json (SchemaDiff reports "became guarded"), a post_install_message explains the change on bundle update, and Graphiti.guarded_relationships lists affected relationships. Also fixes relationship condition blocks mutating a hash shared across the serializer class hierarchy, which let one resource's guard affect same-named relationships on sibling serializers. Co-authored-by: Jeff Keen <[email protected]>
jkeen
pushed a commit
to jkeen/graphiti
that referenced
this pull request
Jul 30, 2026
# [1.12.0](graphiti-api/graphiti@v1.11.1...v1.12.0) (2026-07-29) ### Bug Fixes * GQL name chaining ([graphiti-api#415](graphiti-api#415)) [skip ci] ([930928a](graphiti-api@930928a)) ### Features * conditional relationships evaluate readable/writable guards per-request ([graphiti-api#450](graphiti-api#450)) ([3ed3187](graphiti-api@3ed3187)) * pass the model and attribute name to writable guards ([graphiti-api#511](graphiti-api#511)) [skip ci] ([24a8a94](graphiti-api@24a8a94))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
History
Setting the
readableoption on a relationship to a callables (procs, lambdas, etc) would only evaulate on load (once). Conditionally hiding relationships per request was not supported. Feature was disabledCurrent State (before PR)
readableoption on relationships (has_many,belongs_to) doesn't support callables (procs, lambdas, etc).This PR
Adds support for setting
readablewith callables.Changes
Sideloadevaluates readable flag every time so that the read conditions can be check against current request (or context):ifoption onJSONAPI::Serializable::Relationshipobject with lambda that callssideload.readable?readable?on sideload since the check will be happening in the serializer.include_hashif the current included relationships is not readable.Update (July 2026)
The branch has grown since the original description:
readable:/writable:accept symbols, strings, and procs, evaluated per-request. Unreadable relationships are omitted from responses and scrubbed from?include=; unwritable ones reject sideposting withunwritable_relationship.?include=, before any records exist, so they can only depend on request context.true. Upgrading enforces them, so formerly-succeeding reads/writes may be denied. Upgraders are covered three ways: the schema check reportsrelationship :x became guarded, a gem post-install message explains the change, andbin/rails runner 'puts Graphiti.guarded_relationships'lists every affected relationship.