graphql-armory 0.1.0.pre13 → 0.1.0.pre14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/README.md +5 -5
  4. data/docs/authorization.md +4 -0
  5. data/docs/encrypted-ids.md +24 -2
  6. data/docs/persisted-queries.md +4 -0
  7. data/docs/rate-limiting.md +23 -0
  8. data/docs/response-caching.md +590 -0
  9. data/docs/subscriptions.md +261 -0
  10. data/docs/telemetry.md +39 -1
  11. data/docs/versioning.md +4 -0
  12. data/lib/graphql/armory/authorization/authorize.rb +3 -0
  13. data/lib/graphql/armory/authorization/scope.rb +2 -0
  14. data/lib/graphql/armory/caching/audit/command.rb +51 -0
  15. data/lib/graphql/armory/caching/audit/context_class.rb +117 -0
  16. data/lib/graphql/armory/caching/audit/declarations.rb +166 -0
  17. data/lib/graphql/armory/caching/audit/own_checks.rb +150 -0
  18. data/lib/graphql/armory/caching/audit/public_rules.rb +158 -0
  19. data/lib/graphql/armory/caching/audit/report.rb +113 -0
  20. data/lib/graphql/armory/caching/audit.rb +136 -0
  21. data/lib/graphql/armory/caching/base.rb +118 -0
  22. data/lib/graphql/armory/caching/canonical.rb +138 -0
  23. data/lib/graphql/armory/caching/charge.rb +86 -0
  24. data/lib/graphql/armory/caching/codec.rb +108 -0
  25. data/lib/graphql/armory/caching/context_methods.rb +88 -0
  26. data/lib/graphql/armory/caching/controls/app_schema.rb +70 -0
  27. data/lib/graphql/armory/caching/controls/context.rb +30 -0
  28. data/lib/graphql/armory/caching/controls/operations.rb +37 -0
  29. data/lib/graphql/armory/caching/controls/schema.rb +123 -0
  30. data/lib/graphql/armory/caching/controls/store.rb +16 -0
  31. data/lib/graphql/armory/caching/controls/walk_schema.rb +197 -0
  32. data/lib/graphql/armory/caching/controls.rb +19 -0
  33. data/lib/graphql/armory/caching/digester.rb +48 -0
  34. data/lib/graphql/armory/caching/errors.rb +16 -0
  35. data/lib/graphql/armory/caching/gate/admission.rb +67 -0
  36. data/lib/graphql/armory/caching/gate/signals.rb +65 -0
  37. data/lib/graphql/armory/caching/gate/store_check.rb +60 -0
  38. data/lib/graphql/armory/caching/gate/substitute.rb +61 -0
  39. data/lib/graphql/armory/caching/gate.rb +384 -0
  40. data/lib/graphql/armory/caching/integration/guard.rb +55 -0
  41. data/lib/graphql/armory/caching/integration/install.rb +262 -0
  42. data/lib/graphql/armory/caching/integration/query.rb +42 -0
  43. data/lib/graphql/armory/caching/integration.rb +141 -0
  44. data/lib/graphql/armory/caching/keyer.rb +208 -0
  45. data/lib/graphql/armory/caching/memory_store.rb +164 -0
  46. data/lib/graphql/armory/caching/nulls.rb +121 -0
  47. data/lib/graphql/armory/caching/purge.rb +98 -0
  48. data/lib/graphql/armory/caching/record_keys.rb +109 -0
  49. data/lib/graphql/armory/caching/recorder/context.rb +178 -0
  50. data/lib/graphql/armory/caching/recorder/log.rb +142 -0
  51. data/lib/graphql/armory/caching/recorder/null.rb +24 -0
  52. data/lib/graphql/armory/caching/recorder/shared_writes.rb +58 -0
  53. data/lib/graphql/armory/caching/recorder/substitute.rb +119 -0
  54. data/lib/graphql/armory/caching/recorder.rb +34 -0
  55. data/lib/graphql/armory/caching/redis_store/scripts.rb +159 -0
  56. data/lib/graphql/armory/caching/redis_store.rb +162 -0
  57. data/lib/graphql/armory/caching/rspec.rb +25 -0
  58. data/lib/graphql/armory/caching/schema_identity.rb +102 -0
  59. data/lib/graphql/armory/caching/store/null.rb +31 -0
  60. data/lib/graphql/armory/caching/store/substitute.rb +144 -0
  61. data/lib/graphql/armory/caching/store.rb +34 -0
  62. data/lib/graphql/armory/caching/tags.rb +39 -0
  63. data/lib/graphql/armory/caching/values/decision.rb +45 -0
  64. data/lib/graphql/armory/caching/values/declaration.rb +114 -0
  65. data/lib/graphql/armory/caching/values/entry.rb +108 -0
  66. data/lib/graphql/armory/caching/values/key.rb +39 -0
  67. data/lib/graphql/armory/caching/values/lookup.rb +35 -0
  68. data/lib/graphql/armory/caching/values/policy.rb +44 -0
  69. data/lib/graphql/armory/caching/viewer.rb +112 -0
  70. data/lib/graphql/armory/caching/walk/directives.rb +45 -0
  71. data/lib/graphql/armory/caching/walk/relay.rb +54 -0
  72. data/lib/graphql/armory/caching/walk/run.rb +130 -0
  73. data/lib/graphql/armory/caching/walk/tally.rb +38 -0
  74. data/lib/graphql/armory/caching/walk.rb +46 -0
  75. data/lib/graphql/armory/caching.rb +69 -0
  76. data/lib/graphql/armory/encoder/legacy.rb +14 -0
  77. data/lib/graphql/armory/encoder/null.rb +14 -1
  78. data/lib/graphql/armory/encoder/substitute.rb +54 -2
  79. data/lib/graphql/armory/encoder/versioned.rb +36 -0
  80. data/lib/graphql/armory/encoder.rb +80 -1
  81. data/lib/graphql/armory/persisted_queries.rb +8 -1
  82. data/lib/graphql/armory/rate_limits/cached_charge.rb +43 -0
  83. data/lib/graphql/armory/rate_limits/concurrency.rb +12 -5
  84. data/lib/graphql/armory/rate_limits/invalid_queries.rb +3 -2
  85. data/lib/graphql/armory/rate_limits/points.rb +21 -9
  86. data/lib/graphql/armory/rate_limits/time.rb +15 -8
  87. data/lib/graphql/armory/rate_limits.rb +9 -0
  88. data/lib/graphql/armory/subscriptions/ably/key.rb +49 -0
  89. data/lib/graphql/armory/subscriptions/ably/publisher.rb +132 -0
  90. data/lib/graphql/armory/subscriptions/ably/token_request.rb +42 -0
  91. data/lib/graphql/armory/subscriptions/ably/webhook.rb +96 -0
  92. data/lib/graphql/armory/subscriptions/ably.rb +126 -0
  93. data/lib/graphql/armory/subscriptions/audit.rb +92 -0
  94. data/lib/graphql/armory/subscriptions/controls/dependencies.rb +37 -0
  95. data/lib/graphql/armory/subscriptions/controls/event_log.rb +30 -0
  96. data/lib/graphql/armory/subscriptions/controls/id.rb +26 -0
  97. data/lib/graphql/armory/subscriptions/controls/record.rb +34 -0
  98. data/lib/graphql/armory/subscriptions/controls/schema.rb +187 -0
  99. data/lib/graphql/armory/subscriptions/controls/viewer.rb +99 -0
  100. data/lib/graphql/armory/subscriptions/controls.rb +19 -0
  101. data/lib/graphql/armory/subscriptions/core/channels.rb +93 -0
  102. data/lib/graphql/armory/subscriptions/core/clock.rb +40 -0
  103. data/lib/graphql/armory/subscriptions/core/controls.rb +29 -0
  104. data/lib/graphql/armory/subscriptions/core/delivery.rb +250 -0
  105. data/lib/graphql/armory/subscriptions/core/settings.rb +182 -0
  106. data/lib/graphql/armory/subscriptions/core/trigger.rb +63 -0
  107. data/lib/graphql/armory/subscriptions/core/viewer.rb +153 -0
  108. data/lib/graphql/armory/subscriptions/core/write.rb +172 -0
  109. data/lib/graphql/armory/subscriptions/core.rb +200 -0
  110. data/lib/graphql/armory/subscriptions/errors.rb +30 -0
  111. data/lib/graphql/armory/subscriptions/http/null.rb +17 -0
  112. data/lib/graphql/armory/subscriptions/http/substitute.rb +56 -0
  113. data/lib/graphql/armory/subscriptions/http.rb +93 -0
  114. data/lib/graphql/armory/subscriptions/memory_store.rb +115 -0
  115. data/lib/graphql/armory/subscriptions/pusher/signature.rb +45 -0
  116. data/lib/graphql/armory/subscriptions/pusher.rb +192 -0
  117. data/lib/graphql/armory/subscriptions/redis_store/scripts.rb +115 -0
  118. data/lib/graphql/armory/subscriptions/redis_store.rb +157 -0
  119. data/lib/graphql/armory/subscriptions/store/null.rb +23 -0
  120. data/lib/graphql/armory/subscriptions/store/substitute.rb +155 -0
  121. data/lib/graphql/armory/subscriptions/store.rb +38 -0
  122. data/lib/graphql/armory/subscriptions/topic.rb +253 -0
  123. data/lib/graphql/armory/subscriptions/transport/null.rb +28 -0
  124. data/lib/graphql/armory/subscriptions/transport/substitute.rb +150 -0
  125. data/lib/graphql/armory/subscriptions/transport.rb +41 -0
  126. data/lib/graphql/armory/subscriptions/values/capabilities.rb +50 -0
  127. data/lib/graphql/armory/subscriptions/values/message.rb +31 -0
  128. data/lib/graphql/armory/subscriptions/values/outcome.rb +42 -0
  129. data/lib/graphql/armory/subscriptions/values/record.rb +176 -0
  130. data/lib/graphql/armory/subscriptions/webhook_app.rb +31 -0
  131. data/lib/graphql/armory/subscriptions.rb +33 -0
  132. data/lib/graphql/armory/telemetry.rb +8 -4
  133. data/lib/graphql/armory/version.rb +1 -1
  134. data/lib/graphql/armory/versioning/integration.rb +2 -1
  135. data/lib/graphql/armory.rb +2 -0
  136. data/lib/tasks/graphql_armory.rake +9 -0
  137. metadata +110 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e1c1031aac2b8bb370345a622fb7d74403aa06594656cf72b4178469364db71
4
- data.tar.gz: e0a45f56b54f68e2118eeb3ace191ce138cf48f2e120b8c9ac79d29dbcc77a3a
3
+ metadata.gz: 60c5c0dcce6269bada949c9a3bcfcd5de843bef80c81c721fc577eb95aa6793f
4
+ data.tar.gz: b4f86066c3d298a14e7762467d1302cdd8f42b695f8218cff0e75bfaee053501
5
5
  SHA512:
6
- metadata.gz: '08b594e550521e1fa3b9c2677b6c104fa84713156bfd62a7e6a32c5accb843ff9281e87d2333d8c6bdb7cb110f05c37a65c057a085ff2b21f63b30320dc2b4f0'
7
- data.tar.gz: 16d4f937c3083050a8c7a12263614597bfd5f40461e3ebf07892dc385215505a7e2f00448daf19a00593de27a26608667c3d30feec5125d0941bc336d61f9a44
6
+ metadata.gz: 86ddf1c6c14fda0da7a1508462cf1aad860ace99eab0f80e75ef6b9533f0156de762e5f207c92bda4390745b945dcbfe86f3d71e2829e117f13276ddce5b6833
7
+ data.tar.gz: 4b28de723a5013ab17fd7183dbdf2e1e97418b5080478dab7903d13e09a787b53f200a8d3a531515c6359501d22139941de9c7819674ff9880f448b59dba976d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.0.pre14 (2026-11-05)
4
+
5
+ This release adds [response caching](docs/response-caching.md) and [subscriptions over hosted pub/sub](docs/subscriptions.md). The cache answers a repeated persisted operation from a store, and stores an answer only when nothing it could not see took part in it, with an audit that finds unsafe declarations before production. Subscriptions run graphql-ruby subscriptions over Pusher, Ably or any transport of the same shape, with each update delivered as its own subscriber, never broadcast, and ended when the subscriber loses access. Upgrade if you need either; nothing existing changes for a schema that does not install them, except that rate limiting no longer charges subscription deliveries.
6
+
7
+ ### Added
8
+
9
+ - Subscriptions over hosted pub/sub: graphql-ruby subscriptions delivered through Pusher, Ably or any transport with the same shape, without a provider SDK and without one subscriber's update reaching another. `use GraphQL::Armory::Subscriptions, store: GraphQL::Armory::Subscriptions::RedisStore.build(redis:, prefix:), transport: GraphQL::Armory::Subscriptions::Pusher.build(app_id:, key:, secret:, cluster:), encoder: AppEncoder, viewer: { dump:, load:, sets: }, context_keys: { tenant_id: "reason" }, max_lifetime: 86_400` installs the backend. It replaces four graphql-ruby defaults that are unsafe with more than one user: a trigger's `context:` is refused instead of being merged over each subscriber's (each delivery rebuilds the subscriber's own context from its sealed record and reloads the viewer, on the engine that created it, through Authorization, Versioning and PersistedQueries); topics are keyed digests of a canonical JSON built through each argument's definition, so `room(id: "5:thread:9")` and the scopes `1` and `"1"` no longer collide; a subscriber whose update has no data or a null root field (a denied root under the default `on_unauthorized: :null`) gets that last result with `more: false` and is unsubscribed; and nothing is broadcast. The server builds every subscription id (a client-set `context[:subscription_id]` is refused), channels are authorized only for the viewer that created them (`authorize_channel` for Pusher private channels, `authorize_viewer` for an Ably TokenRequest scoped to the viewer's own channels), records are sealed with your `Encoder`, and every subscription ends by `max_lifetime`; `WebhookApp` ends one sooner on a verified Pusher `channel_vacated` or Ably presence `leave`. `max_per_viewer:`, `max_per_topic:` and `max_executions_per_trigger:` bound the work, a result over the transport's limit is sent as `RESULT_TOO_LARGE`, `trigger(..., version:)` serves a Versioning `default: :refuse` schema, and the `:subscription_*` signals carry no id, viewer or result ([Telemetry](docs/telemetry.md#subscriptions)). `Subscriptions::Audit.call(schema)` lists broadcastable fields, anonymous mode and each stored context key. The MIT `graphql-ruby-client` `PusherLink` and `AblyLink` work unchanged. Limits: triggers run in the calling process, one execution per subscriber; between a permission change and the next trigger the subscription still exists; webhooks are late and lossy (`max_lifetime` bounds a subscription); arguments with `loads:` or `prepare:` are refused; no ActionCable, AnyCable or broadcast transport. [Subscriptions](docs/subscriptions.md). (#78)
10
+ - Response caching: a repeated persisted operation is answered from a store without running, and an answer is stored only when nothing the cache could not see took part in it. `use GraphQL::Armory::Caching, store: GraphQL::Armory::Caching::MemoryStore.new, release: ENV.fetch("GIT_SHA"), viewer: :current_user` (after `use GraphQL::Armory::PersistedQueries`, and before any `rescue_from`) hooks every request on both engines. You declare what may be cached: `include GraphQL::Armory::Caching::Base` in your base field, object and interface classes gives `cache_fields ttl: 300, scope: :public, tags: ["catalog"], reason: "..."` on a type and `cache: { ttl: 60 }` or `cache: false` on a field, where a field may only narrow its type; `cache_safe reason: "..."` on a directive that does not change the data. An operation is cached only if every field it selects is declared, for the smallest TTL among them (`scope: :viewer` by default, `:public` only if all are, and it needs a `reason:`). A `:viewer` answer is served only to the same principal (class and id), and an anonymous request is cached only with `anonymous: :shared, anonymous_reason: "..."`. The key is a keyed digest of the release, the schema (per version and visibility profile), the engine, the document, the declared variables, the resolved version, the limits, the scope, the viewer and your `vary:` values (a context key, or a callable for what the cache cannot see: `Current`, `I18n.locale`). While the run that would fill the cache executes, the context records every key it reads: a read the key does not hold (`:context_read`), a write to a covered key, an answer with errors, non-JSON data or a `rescue_from` handler's answer, and a `:public` answer that consulted an authorization policy are not stored. A public method your own `context_class` adds must be named in `context_methods:` with a reason, or queries on it run uncached (`:context_method`). Never cached: raw queries, mutations (and any query in a call that holds one), subscriptions, introspection, queries your own code builds, `run_partials`, and requests with `warden:`, `static_validator:`, `root_value:`, `use_visibility_profile:` or `validate: false`. `MemoryStore` and `RedisStore.build(redis:, encoder:)` keep the answers: one atomic Lua script per Redis operation, purge marks that are never evicted, `purge_replicas:` to wait for replicas. Entries are JSON sealed with your `Encoder` (required with Redis), and keys and tags are keyed digests, so nothing in the store names a viewer, tag, variable or operation. `GraphQL::Armory::Caching.purge(schema, all: true | viewer: user | tag: "pricing" | type: Types::Invoice)` purges by tag digest (`type:` is best effort), a run that started before a purge cannot undo it, a store reset counts as a purge of everything, and a store failure raises `PurgeError`. A store that fails on a lookup or write runs the query uncached (`on_store_error:`); a schema graphql-ruby cannot print (graphql 2.4 with json 3.x) runs uncached (`:schema_unprintable`). `max_ttl:` (3600) and `max_viewer_ttl:` (300, at most 300) cap every TTL, and `use` raises `ConfigurationError` at boot when `max_ttl:` is larger than the store's own. `context[:response_cache]` tells a controller `{ status:, reason:, scope:, ttl:, age: }`, `extensions: true` adds `"cache" => { "hit" => true, "age" => n }` to a hit, `Caching.neutral(context) { ... }` lets a tracer or logger read the context without keeping an answer out of the cache, and the signals `:cache_hit`, `:cache_stored`, `:cache_skipped`, `:cache_entry_rejected`, `:cache_store_failed` and `:cache_purged` carry only reasons, scopes and TTLs ([Telemetry](docs/telemetry.md#response-caching)). Limits: the cache cannot see the database, the clock, `ENV`, a thread-local tenant or the state of an object in the context, and a `:public` declaration is your promise that you put them in `vary:`; a revoked permission keeps serving the same viewer until the TTL ends or `purge(viewer:)` runs; a hit runs no resolver, tracer or multiplex analyzer; there is no HTTP caching and no stampede protection. [Response caching](docs/response-caching.md). (#77)
11
+ - `Caching::Audit.(AppSchema)`, `expect(AppSchema).to have_safe_cache_declarations` (`require "graphql/armory/caching/rspec"`) and `rake "graphql_armory:cache:audit[AppSchema]"` report, before production, a `:public` declaration over a field Authorization decides per user (`:public_over_rule`), your own `visible?`, `authorized?` or `scope_items` on a class it reaches (`:own_check`, declared with `own_checks:`), a context class the recorder cannot see through (`:context_class`), TTLs above the limits, `:viewer` declarations with no `viewer:`, declarations never used, and a plugin installed without PersistedQueries, and list every declaration with its reason. Limit: `ok?` covers only what Authorization's checks decide. [The audit](docs/response-caching.md#the-audit). (#77)
12
+ - `Encoder.seal(bytes, aad:, purpose:)` and `Encoder.open(text, aad:, purpose:)` (AES-256-GCM under a key derived for each purpose, binding the additional data and the tag) and `Encoder.mac(bytes, purpose:)` (keyed 32-byte digests), on encoders and versioned chains; `Legacy` and `Null` refuse. IDs and cursors are unchanged byte for byte. Response caching uses them to seal its entries and name its keys. [Sealing other data](docs/encrypted-ids.md#sealing-other-data). (#77)
13
+ - Rate limiting charges a response served by the response cache the `Points` its run cost (`Points#charge_cached`), with the run's keys, limits, soft mode, records, `rateLimit` extension, headers and `RATE_LIMITED` refusal, so a cached answer is neither a bypass of the budget nor a way to learn that someone else asked first. Limit: `Time` does not bound cached responses and `Concurrency` takes no slot for them. [Cached responses](docs/rate-limiting.md#cached-responses). (#77)
14
+
15
+ ### Changed
16
+
17
+ - Rate limiting charges nothing for a subscription delivery: `Points`, `Time`, `Concurrency` and invalid-query charges skip a query the subscriptions backend marked in `context.namespace(:armory)`, a namespace a request cannot write, so a delivery needs no `rate_limit_key` and nobody who causes triggers can spend another user's budget. A request is charged as before. [Subscriptions](docs/subscriptions.md#the-solution). (#78)
18
+ - PersistedQueries marks the queries that run a stored operation in a namespace of the context a client cannot write (`context.namespace(:armory)[:persisted]`), and Authorization marks a query wherever a policy or ability is consulted (`context.namespace(:armory)[:viewer_dependent]`; never for an `authorize :none` bypass). Versioning's read of `armory_version`, Telemetry's sinks and the rate limiters' key, limit and exemption lookups read the context through `Caching.neutral`, so response caching does not count those reads. Nothing changes for a schema that does not use response caching. [With response caching](docs/persisted-queries.md#with-response-caching). (#77)
19
+
3
20
  ## 0.1.0.pre13 (2026-11-04)
4
21
 
5
22
  This release adds [API versioning](docs/versioning.md): each client gets the schema of the version it names, so fields, arguments, enum values and types can arrive, be deprecated and leave without breaking older clients. It comes with an audit that finds, before production, every query a version would refuse and every member it would serve or leave out by mistake, plus a diff and an SDL dump per version. Upgrade if you need to evolve a public schema; nothing existing changes.
data/README.md CHANGED
@@ -6,12 +6,12 @@
6
6
 
7
7
  Open-source extensions for [graphql-ruby](https://github.com/rmosolgo/graphql-ruby), built on its public extension points: no fork, no monkey patching. One gem, one module at a time; each module has its own page in [`docs/`](docs) with the problem it solves, how to use it, and its limits.
8
8
 
9
- > **Status: early development.** Prereleases on RubyGems (`0.1.0.pre13`). The API may change before 1.0.
9
+ > **Status: early development.** Prereleases on RubyGems (`0.1.0.pre14`). The API may change before 1.0.
10
10
 
11
11
  ## Install
12
12
 
13
13
  ```ruby
14
- gem "graphql-armory", "~> 0.1.0.pre13" # a prerelease: `gem install graphql-armory --pre`
14
+ gem "graphql-armory", "~> 0.1.0.pre14" # a prerelease: `gem install graphql-armory --pre`
15
15
  gem "pundit" # or "cancancan", for the authorization module
16
16
  ```
17
17
 
@@ -25,11 +25,11 @@ Status: ✅ released, 🚧 in progress, ⬜ not started. Update this table in th
25
25
  |---|---|---|---|---|
26
26
  | 1 | Authorization (Pundit, CanCanCan) | ✅ | [docs/authorization.md](docs/authorization.md) | Released in 0.1.0.pre2 (prerelease). Pundit and CanCanCan (the audit checks less with CanCanCan). Global IDs in `loads:` decoded through `object_from_id`; `loads:` inside input objects scoped with `include Base`. `Execution::Next` needs graphql >= 2.6.2. The audit gives the file and line of each problem from 0.1.0.pre11, and of generated payloads and connections from 0.1.0.pre12. |
27
27
  | 2 | Encrypted, versioned IDs and cursors | ✅ | [docs/encrypted-ids.md](docs/encrypted-ids.md) | Released in 0.1.0.pre4 (prerelease). `Encoder` (AES-256-GCM), versioned chains and `Legacy`, `Encoder.default` (ENV or Rails), `use GraphQL::Armory::IDs`. Composite primary keys not supported. |
28
- | 3 | Persisted queries / operation allowlist | ✅ | [docs/persisted-queries.md](docs/persisted-queries.md) | Released in 0.1.0.pre4 (prerelease). Operations can be published without a server deploy (`RedisStore`, unreleased). Allowlist from a build manifest (Apollo, Relay), `use GraphQL::Armory::PersistedQueries` with strict mode. A runtime store (database, sync endpoint) is planned for later. |
28
+ | 3 | Persisted queries / operation allowlist | ✅ | [docs/persisted-queries.md](docs/persisted-queries.md) | Released in 0.1.0.pre4 (prerelease). Operations can be published without a server deploy (`RedisStore`, from 0.1.0.pre9). Allowlist from a build manifest (Apollo, Relay), `use GraphQL::Armory::PersistedQueries` with strict mode. A runtime store (database, sync endpoint) is planned for later. |
29
29
  | 4 | Rate limiting | ✅ | [docs/rate-limiting.md](docs/rate-limiting.md) | Released in 0.1.0.pre5 (prerelease); `RateLimits::Time` in 0.1.0.pre6. Points per client (query complexity) and operations at the same time, `MemoryStore` and `RedisStore`, the budget in response extensions and headers. `RateLimits::Time` charges the wall-clock milliseconds operations take. Invalid queries are charged `invalid_cost:` from 0.1.0.pre10. |
30
30
  | 5 | Stable (keyset) connections | ✅ | [docs/keyset-connections.md](docs/keyset-connections.md) | Released in 0.1.0.pre7 (prerelease). `Keyset.build(relation)` per resolver, ActiveRecord only, plain non-null columns of the relation's own table. Base64 cursors refused unless `plain_cursors: true`. No total count. `use` checks the cursor encoder when the schema loads, from 0.1.0.pre10. |
31
- | 6 | Subscriptions over Pusher / Ably | ⬜ | | Research not started. |
32
- | 7 | Response caching | ⬜ | | Research not started. |
31
+ | 6 | Subscriptions over hosted pub/sub | ✅ | [docs/subscriptions.md](docs/subscriptions.md) | Released in 0.1.0.pre14 (prerelease). A provider-agnostic backend (`MemoryStore`, `RedisStore`) with Pusher and Ably transports over plain HTTP, no SDK. Each delivery runs as its subscriber (never with the trigger's context), through Authorization, Versioning and PersistedQueries; a subscriber who loses access is unsubscribed; topics are collision-free keyed digests; nothing is broadcast; channels are bound to their viewer; records are sealed; every subscription ends by `max_lifetime`. Triggers run in-process, one execution per subscriber. |
32
+ | 7 | Response caching | ✅ | [docs/response-caching.md](docs/response-caching.md) | Released in 0.1.0.pre14 (prerelease). Persisted operations only, declared per field and type (`cache_fields`, `cache:`), `:viewer` or `:public` scope, `MemoryStore` and `RedisStore` (sealed with an `Encoder`), purge by tag, type, viewer or everything, hits charged their `Points`, and an audit (`have_safe_cache_declarations`, `rake graphql_armory:cache:audit`). The cache cannot see inputs outside the context (`Current`, the clock, a thread-local tenant): put them in `vary:`. |
33
33
  | 8 | API versioning | ✅ | [docs/versioning.md](docs/versioning.md) | Released in 0.1.0.pre13 (prerelease). Versions per request (`context[:armory_version]`) with refusal codes and a required `default:` policy; `added:`/`removed:` on fields, arguments, enum values, types and memberships, and two definitions of one name to change its shape; `deprecated:` from one version on; an audit (`have_consistent_versions`, `rake graphql_armory:versions:audit`) of what each served version would refuse, serve outside its lifecycle or leave out; a diff of two versions (`have_no_breaking_changes`, `rake graphql_armory:versions:diff`) and a per-version SDL dump; and `profiles: true`, one `Schema::Visibility` profile per version (graphql 2.4.10 or later). |
34
34
  | 9 | `@defer` / `@stream` | ⬜ | | Research not started. |
35
35
  | 10 | Dashboard | ⬜ | | Research not started. |
@@ -476,6 +476,10 @@ use GraphQL::Armory::Authorization, adapter: :pundit,
476
476
 
477
477
  Signals are `:allowed`, `:denied`, `:observed` (a rule under `observe:` would have refused; its data also holds the `reason`), `:bypassed` (an `authorize :none` rule ran) and `:scoped` (a list went through the user's scope). Data holds only `type`, `action` and `reason`, never record attributes. `GraphQL::Armory::Telemetry::Notifications` reports them to `ActiveSupport::Notifications`. Every signal, what to watch for and how to test it: [Telemetry](telemetry.md). A `sinks:` that is not an Array of callables raises `Telemetry::ConfigurationError` at boot.
478
478
 
479
+ ## With response caching
480
+
481
+ A shared answer must not depend on who asked. Wherever a request makes the adapter consult a policy or ability, the query is marked as viewer-dependent (`context.namespace(:armory)[:viewer_dependent]`), and [response caching](response-caching.md) never stores it as an answer shared by every viewer: object and field rules, a scoped list, a `find_by:` or `loads:` lookup through the scope (even for an id that matches nothing), the check of a record an in-memory scope found, `visible_when:`, and a denial as much as an allowed check. An `authorize :none` bypass consults nothing and marks nothing, for an object or a list, so data behind bypasses alone can be shared. The adapter's read of the user from the context is recorded like any other context read, never exempted: an answer computed for a user the cache key does not identify is not stored.
482
+
479
483
  ## Guarantees and limits
480
484
 
481
485
  Covered by the black-box suite in `spec/security`, on both engines: user A cannot read user B's objects by root field, nested association or `loads:`; lists never contain foreign objects; uncovered types fail closed and show in the audit; a field hidden with `visible?` is absent from introspection and error suggestions (that is graphql-ruby's behaviour, pinned by a test).
@@ -120,7 +120,26 @@ The signal never holds the ID, the key or the record. A rising `:invalid` is som
120
120
 
121
121
  ### Testing with IDs
122
122
 
123
- `Encoder::Substitute` encodes reversibly without a key and records what it encoded and decoded, for specs of code that uses an encoder; never hand out real IDs with it. `IDs::Controls::Encoder.example` is an Encoder subclass with a fixed test key, and `IDs::Controls::Record.example(id:)` a record to build IDs from. `IDs::Lookup.new`, with nothing wired, hands out no ID and honours none (`Encoder::Null`); `IDs::Lookup.build(encoder:, find:)` takes the same settings as `use`.
123
+ `Encoder::Substitute` encodes reversibly without a key and records what it encoded and decoded (and what it sealed, opened and digested, in `sealed`, `opened` and `macs`), for specs of code that uses an encoder; never hand out real IDs with it. `IDs::Controls::Encoder.example` is an Encoder subclass with a fixed test key, and `IDs::Controls::Record.example(id:)` a record to build IDs from. `IDs::Lookup.new`, with nothing wired, hands out no ID and honours none (`Encoder::Null`); `IDs::Lookup.build(encoder:, find:)` takes the same settings as `use`.
124
+
125
+ ## Sealing other data
126
+
127
+ The same encoder seals data your app stores and must get back untouched, and gives keyed digests. [Response caching](response-caching.md) uses both to seal its entries and to name its keys and tags; you rarely call them yourself.
128
+
129
+ ```ruby
130
+ blob = AppEncoder.seal(bytes, aad: "invoice-cache:42", purpose: "cache")
131
+ AppEncoder.open(blob, aad: "invoice-cache:42", purpose: "cache") # => the bytes, binary
132
+ AppEncoder.mac("viewer:7", purpose: "cache-digest") # => 32 raw bytes (HMAC-SHA256)
133
+ ```
134
+
135
+ - **`seal`** encrypts with AES-256-GCM and a random nonce, and answers base64url text (whatever `codec` IDs use). `aad`, the additional data, is authenticated but not stored: say where the value belongs (a store key), and a value copied anywhere else does not open.
136
+ - **`open`** answers the bytes only for the same `aad`, `purpose`, key and tag; anything else raises `InvalidError`, without saying why.
137
+ - **`mac`** answers the raw 32-byte HMAC, the same every time, so equal inputs give equal digests and whoever sees a digest cannot confirm a guess without the key.
138
+ - **Each purpose has its own key**, derived from yours with HKDF exactly as the ID and cursor keys are, under another name: a sealed value is never accepted as an ID or a cursor, an ID never opens as a sealed value, and `cache` values never open as `cache-digest` ones. A purpose is lowercase words joined by dashes.
139
+ - **The tag is bound too**: an app with another tag cannot open your values, and its digests differ.
140
+ - **IDs and cursors do not change**: the same IDs come out byte for byte, and the ones already handed out keep decoding.
141
+ - **In a versioned chain**, `seal` and `mac` use the newest encoder and `open` tries each one, so values sealed before a rotation keep opening while the old encoder stays in the chain. Digests change with the newest key: what was stored under old digests is no longer found.
142
+ - **`Encoder::Legacy` and `Encoder::Null` refuse to seal and to digest** (`ConfigurationError`) and open nothing: neither has a key. A chain whose newest member is `Legacy` refuses too.
124
143
 
125
144
  ## Reference
126
145
 
@@ -139,12 +158,15 @@ The signal never holds the ID, the key or the record. A rising `:invalid` is som
139
158
  | `chain.decode_versioned(text, nonce: false)` | `[data, encoder]`, or `[nil, nil]` when no encoder accepts it. |
140
159
  | `use GraphQL::Armory::IDs, encoder: nil, find: nil, sinks: [], on_sink_error: nil` | Defines `id_from_object` and `object_from_id`; `encoder` defaults to `Encoder.default`; `find:` loads types without `Base`; `sinks:` hears `:id_resolved` and `:id_refused` ([Telemetry](telemetry.md)). |
141
160
  | `Encoder.default` | An encoder keyed by `GRAPHQL_ARMORY_KEY`, else by a key derived with HKDF from Rails' `secret_key_base`; raises `ConfigurationError` without either. |
161
+ | `seal(bytes, aad:, purpose:)` | Base64url text: `bytes` encrypted and authenticated with `aad`, under the key of `purpose`. Also on a chain (newest encoder). |
162
+ | `open(text, aad:, purpose:)` | The sealed bytes, binary, or raises `InvalidError`. Also on a chain (any encoder). |
163
+ | `mac(bytes, purpose:)` | The raw 32-byte HMAC-SHA256 under the key of `purpose`. Also on a chain (newest encoder). |
142
164
 
143
165
  A subclass inherits `key`, `tag` and `codec`, and can override any of them. Passing `nil` to any of them raises `ConfigurationError`, so an unset environment variable fails at boot instead of being ignored.
144
166
 
145
167
  ## Guarantees and limits
146
168
 
147
- Covered by `spec/security/encoder_spec.rb`, `encoder_versioning_spec.rb`, `default_encoder_spec.rb` and `ids_plugin_spec.rb` on both engines: round trips, tampering at several positions, another key, another tag, a cursor used as an ID and the reverse, malformed and truncated input, encrypted pagination and a tampered cursor, rotation and migration from base64 cursors, where the default encoder takes its key, and the plugin answering every ID it cannot honour (foreign, tampered, unknown or non-object type, another model in `loads:`) like a missing one.
169
+ Covered by `spec/security/encoder_spec.rb`, `encoder_versioning_spec.rb`, `default_encoder_spec.rb`, `ids_plugin_spec.rb` and `spec/graphql/encoder_seal_spec.rb` on both engines (the last also pins IDs and cursors from before sealing existed): round trips, tampering at several positions, another key, another tag, a cursor used as an ID and the reverse, malformed and truncated input, encrypted pagination and a tampered cursor, rotation and migration from base64 cursors, where the default encoder takes its key, and the plugin answering every ID it cannot honour (foreign, tampered, unknown or non-object type, another model in `loads:`) like a missing one.
148
170
 
149
171
  - **Changing the key invalidates every ID and cursor already handed out**, unless the old encoder stays in a versioned chain.
150
172
  - **`Legacy` in a chain can be forged**, and it does not separate IDs from cursors. Keep it only while migrating.
@@ -263,6 +263,10 @@ use GraphQL::Armory::PersistedQueries, store: PERSISTED, strict: true, sinks: [c
263
263
 
264
264
  A signal holds only the reason. To know who sent the request, a sink that takes three arguments receives the query's context, as in [Telemetry](telemetry.md#who-asked). Do not strike on `:unknown_operation`: after a deploy it is a legitimate client build whose operations are not in the manifest yet. The example has not been run against a live detector.
265
265
 
266
+ ### With response caching
267
+
268
+ [Response caching](response-caching.md) serves and stores answers only for persisted operations. The query that runs a stored operation is marked in a namespace of its context that the client cannot write (`context.namespace(:armory)[:persisted]`), unlike `operation_id`, which the client chooses. Nothing else is marked: not a raw query, whether `strict: false` or `armory_allow_raw_query: true` lets it run and even when it carries the text of a stored operation, not a refused request, and not a `GraphQL::Query` your app builds itself.
269
+
266
270
  ### Testing with persisted queries
267
271
 
268
272
  `PersistedQueries::Store::Substitute.new(*queries)` holds the given queries under their SHA-256, like an Apollo manifest, and records the ids it was asked for (`fetched`). `PersistedQueries::Controls::Operations`, `Query.example` and `Root.example` are a small schema and its operations to test against. The decision itself is `PersistedQueries::Gate`: `Gate.build(store:, strict:)` takes the same settings as `use`, and `gate.(context, query_text, document)` answers `[refusal, document]`. `Gate.new`, with nothing wired, refuses every request (`Store::Null`, strict).
@@ -223,6 +223,8 @@ Soft mode (the default), per-key limits (`limit: ->(key, query) { ... }`) and `o
223
223
 
224
224
  To test it, inject a clock: `Time` takes `clock:` (a callable answering seconds), and `RateLimits::Clock::Substitute` is one your test moves. `Controls::Time.example(clock, seconds: 0.25)` is a root for `Controls::Query.example` whose every field takes that long on the clock.
225
225
 
226
+ `Time` does not bound answers served from the [response cache](response-caching.md): a hit runs nothing, so it has no time to charge. Only `Points` charges a hit (see [Cached responses](#cached-responses)). If you rely on `Time` alone to bound expensive reads, cached reads are outside it.
227
+
226
228
  ### Rolling it out
227
229
 
228
230
  1. Install it in soft mode (leave out `soft:`). Queries run as before; each one records what it cost.
@@ -252,6 +254,26 @@ end
252
254
 
253
255
  The gem does not depend on the redis gem: add it to your Gemfile. A single `Redis` client is safe to share between threads.
254
256
 
257
+ ### Cached responses
258
+
259
+ With the [response cache](response-caching.md), a query can be answered from the cache without running. A hit runs no analyzer, so without help it would be free: a bypass of the budget, and an oracle, since a client that sees its budget not move learns that someone else asked the same question first. So the cache charges each hit through `Points`:
260
+
261
+ - **A hit costs the `Points` its run cost.** When a run is stored, the cost it was charged goes with it, read from that query's own record (`result.context.namespace(:graphql_armory)[:points]`), never from `context[:rate_limit_points]`, which queries of a multiplex share. A hit is charged that cost by every `Points` limiter of the schema, exactly as a run: the same keys (one or several), limits, soft mode and store. `context[:rate_limit_points]`, the `rateLimit` extension and `Points.headers(result)` read as they would for a run.
262
+ - **Over budget, the hit is refused with the run's own refusal.** The client gets the same `RATE_LIMITED` error a run would get, and nothing from the cache. In soft mode the hit is charged, recorded `limited: true` and served. A store that fails lets the hit through and calls `on_store_error`, as for a run. A `key:` or `limit:` callable that raises an `ExecutionError` refuses the hit with `RATE_LIMIT_NOT_CHARGED` in hard mode (or with the `AnalysisError` it raised), and serves it with `charged: false` in soft mode, as for a run.
263
+ - **A run that recorded no cost is not stored** when a `Points` limiter is installed (a store that failed, a limiter that could not charge): a hit could not be charged for it.
264
+ - **`Time` does not bound hits**, and **`Concurrency` takes no slot** for one: a hit runs nothing.
265
+
266
+ The limiters read the context to name and limit the client (`key:`, `limit:`, `rate_limit_key`) inside `Caching.neutral`, so those reads do not keep an answer out of the cache: who is charged does not change the answer. A resolver that reads the same keys is still seen. The limiters' own records (`context[:rate_limit_points]` and the others) are not writes of the query either, so a resolver that returns them is seen as reading an input the cache key does not hold, and its answer is not stored.
267
+
268
+ ### Subscription deliveries
269
+
270
+ An update that [Subscriptions](subscriptions.md) delivers is server work a trigger caused, not a request from the
271
+ subscriber, so no limiter charges it: `Points`, `Time`, `Concurrency` and invalid-query charges skip a query the
272
+ backend marked in `context.namespace(:armory)`, which a request cannot write. A delivery needs no `rate_limit_key`.
273
+ The subscribe request itself is charged like any other, and `max_complexity` and `max_depth` still apply to every
274
+ delivery. The subscriptions caps (`max_per_viewer:`, `max_per_topic:`, `max_executions_per_trigger:`) bound the
275
+ deliveries instead.
276
+
255
277
  ### Testing your limits
256
278
 
257
279
  `RateLimits::Store::Substitute` is a `MemoryStore` on a clock your test moves, that records its calls and fails when told, so specs need no mocks and no sleeping:
@@ -347,6 +369,7 @@ Invalid settings raise `RateLimits::ConfigurationError` at boot.
347
369
  - The time is wall-clock, so it grows when the server is loaded: the same query costs a client more on a busy server. Choose `limit` with that in mind, and start in soft mode.
348
370
  - A query run with its own trace (`context: { trace: ... }`) cannot be charged, so it raises `ConfigurationError`, as with `Concurrency`.
349
371
  - When the store fails, operations run unlimited and `on_store_error` is called; a failed charge never raises into the query (unless your hook does).
372
+ - An answer served from the response cache runs nothing and is not charged by `Time`: only `Points` charges a hit ([Cached responses](#cached-responses)).
350
373
 
351
374
  ### Clients that change identity
352
375