rails_audit_log-graphql 0.3.0 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8365cc8fe6ee9823f9cc1ec386fe119675e60fb70214e4fd91e3133c4b1c208
4
- data.tar.gz: 89251a109b0d83c5150fd3b93253a8152421c9eb5bb2ef6ddc2be7304761e451
3
+ metadata.gz: fd228bcaff874e10bbd50927cb3bc44d22b5c860acf8dd444624eff80c7dea96
4
+ data.tar.gz: 29ebf0ccd63fd0827689d3cf0b5e5bd3b4c6194c12468aa347c0fadb1fe0c5f3
5
5
  SHA512:
6
- metadata.gz: dc978f7e8627a1f0449ee93e0abe737eb1e4a5b348d66295fb9630a5714553ea2b4d594a69e55fc682724fbc689493592ad656b217cb17f5150614746416224c
7
- data.tar.gz: b93fdc0c1577144640b5475c7af57407827ffe015d3579aa2d4fd2c1d3b58ccd5b31c891b66790a9c75e745eb4b5c674172d79c0fdd9c3a2dc8a26caa3b00356
6
+ metadata.gz: 81930d3cedc11053354b5b86349d5483b326f43d774ebea49f97bc61e827c1ede95fa61c1b2671c611df266a9f7b4f4e497d472d47d86fc01b9e6863dd2b8df2
7
+ data.tar.gz: 158775764845a120940581a0e6c47be8ca3ba992c5195b4bb899c970d069f27dc94faf53c4dde7ee1e4752992d8de62adec09f3f20a68e8209499239e9589887
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2026-06-04
4
+
5
+ ### Added
6
+
7
+ - `AuditLogEntryCreated` subscription — `auditLogEntryCreated(itemType:, itemId:)` subscribes to new entries for a specific record; `auditLogEntryCreated(actorId:)` subscribes to all entries by a specific actor
8
+ - `AuditLogSubscriptionsMixin` — include into host app's `SubscriptionType` to add the `auditLogEntryCreated` subscription field
9
+ - `BaseSubscription` base class for all gem GraphQL subscription types
10
+ - `Broadcaster` — call `Broadcaster.new(schema: MySchema).start` in an initializer to relay `rails_audit_log.entry_created` `ActiveSupport::Notifications` events into GraphQL subscription triggers; supports `stop` to unsubscribe
11
+
3
12
  ## [0.3.0] - 2026-06-03
4
13
 
5
14
  ### Added
data/README.md CHANGED
@@ -21,6 +21,10 @@ A [graphql-ruby](https://graphql-ruby.org) API layer for the [`rails_audit_log`]
21
21
  - [auditLogEntries](#auditlogentries-auditlogentry)
22
22
  - [auditLogEntriesConnection](#auditlogentriesconnection-auditlogentryconnection)
23
23
  - [Authentication](#authentication)
24
+ - [Subscriptions](#subscriptions)
25
+ - [AuditLogSubscriptionsMixin](#auditlogsubscriptionsmixin)
26
+ - [auditLogEntryCreated](#auditlogentrycreated)
27
+ - [Broadcaster](#broadcaster)
24
28
  - [Development](#development)
25
29
  - [Contributing](#contributing)
26
30
  - [License](#license)
@@ -217,6 +221,84 @@ If no authenticate block is set, all queries are permitted.
217
221
 
218
222
  [↑ Back to top](#table-of-contents)
219
223
 
224
+ ### Subscriptions
225
+
226
+ Requires Action Cable in the host application.
227
+
228
+ #### AuditLogSubscriptionsMixin
229
+
230
+ Include `RailsAuditLog::Graphql::Subscriptions::AuditLogSubscriptionsMixin` into your app's `SubscriptionType` to add the `auditLogEntryCreated` field. Your schema must also use `GraphQL::Subscriptions::ActionCableSubscriptions`.
231
+
232
+ ```ruby
233
+ # app/graphql/types/subscription_type.rb
234
+ class Types::SubscriptionType < Types::BaseObject
235
+ include RailsAuditLog::Graphql::Subscriptions::AuditLogSubscriptionsMixin
236
+ end
237
+
238
+ # app/graphql/my_schema.rb
239
+ class MySchema < GraphQL::Schema
240
+ query Types::QueryType
241
+ subscription Types::SubscriptionType
242
+ use GraphQL::Subscriptions::ActionCableSubscriptions
243
+ end
244
+ ```
245
+
246
+ #### `auditLogEntryCreated`
247
+
248
+ Fires when a new `RailsAuditLog::AuditLogEntry` is created. Accepts one of two argument combinations:
249
+
250
+ | Argument | Type | Description |
251
+ |---|---|---|
252
+ | `itemType` | `String` | Model class name to scope the subscription to |
253
+ | `itemId` | `ID` | Record ID to scope the subscription to |
254
+ | `actorId` | `ID` | Actor ID — subscribe to all entries by a specific actor |
255
+
256
+ Subscribe to all changes on a specific record:
257
+
258
+ ```graphql
259
+ subscription {
260
+ auditLogEntryCreated(itemType: "Post", itemId: "42") {
261
+ id
262
+ event
263
+ diff { attribute from to }
264
+ }
265
+ }
266
+ ```
267
+
268
+ Subscribe to all entries by a specific actor:
269
+
270
+ ```graphql
271
+ subscription {
272
+ auditLogEntryCreated(actorId: "7") {
273
+ id
274
+ event
275
+ itemType
276
+ itemId
277
+ }
278
+ }
279
+ ```
280
+
281
+ #### Broadcaster
282
+
283
+ `RailsAuditLog::Graphql::Subscriptions::Broadcaster` bridges `ActiveSupport::Notifications` (fired by `RailsAuditLog::Streaming::NotificationsAdapter` or `ActiveJobAdapter`) to GraphQL subscription triggers. Start it in an initializer:
284
+
285
+ ```ruby
286
+ # config/initializers/rails_audit_log_graphql.rb
287
+ RailsAuditLog.configure do |c|
288
+ c.streaming_adapter = RailsAuditLog::Streaming::NotificationsAdapter.new
289
+ end
290
+
291
+ Rails.application.config.after_initialize do
292
+ RailsAuditLog::Graphql::Subscriptions::Broadcaster.new(schema: MySchema).start
293
+ end
294
+ ```
295
+
296
+ For each entry, the broadcaster triggers:
297
+ - `auditLogEntryCreated(itemType:, itemId:)` — notifies record-specific subscribers
298
+ - `auditLogEntryCreated(actorId:)` — notifies actor-specific subscribers (when an actor is present)
299
+
300
+ [↑ Back to top](#table-of-contents)
301
+
220
302
  ## Development
221
303
 
222
304
  ```bash
data/ROADMAP.md CHANGED
@@ -4,16 +4,6 @@ This gem adds a GraphQL API layer on top of [`rails_audit_log`](https://github.c
4
4
 
5
5
  ---
6
6
 
7
- ## 0.4.0 — Subscriptions
8
-
9
- Requires Action Cable in the host application.
10
-
11
- - **`auditLogEntryCreated(itemType:, itemId:)`** — subscribe to new entries for a specific record
12
- - **`auditLogEntryCreated(actorId:)`** — subscribe to all entries by a specific actor
13
- - Hooks into `RailsAuditLog::Streaming::NotificationsAdapter` to trigger broadcasts
14
-
15
- ---
16
-
17
7
  ## 0.5.0 — Multi-tenancy & Advanced Filtering
18
8
 
19
9
  - **Tenant scoping** — automatically scope queries via `RailsAuditLog.current_tenant` when configured
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAuditLog
4
+ module Graphql
5
+ module Subscriptions
6
+ class AuditLogEntryCreated < Types::BaseSubscription
7
+ description "Fires when a new audit log entry is created."
8
+
9
+ argument :item_type, String, required: false,
10
+ description: "Filter to entries for a specific model class name."
11
+ argument :item_id, GraphQL::Types::ID, required: false,
12
+ description: "Filter to entries for a specific record ID."
13
+ argument :actor_id, GraphQL::Types::ID, required: false,
14
+ description: "Filter to entries by a specific actor ID."
15
+
16
+ type Types::AuditLogEntryType, null: false
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAuditLog
4
+ module Graphql
5
+ module Subscriptions
6
+ module AuditLogSubscriptionsMixin
7
+ def self.included(base)
8
+ base.field(
9
+ :audit_log_entry_created,
10
+ subscription: AuditLogEntryCreated,
11
+ description: "Fires when a new audit log entry is created."
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAuditLog
4
+ module Graphql
5
+ module Subscriptions
6
+ class Broadcaster
7
+ EVENT = "rails_audit_log.entry_created"
8
+
9
+ def initialize(schema:)
10
+ @schema = schema
11
+ @subscriber = nil
12
+ end
13
+
14
+ def start
15
+ @subscriber = ActiveSupport::Notifications.subscribe(EVENT) do |*, payload|
16
+ broadcast(payload[:entry])
17
+ end
18
+ end
19
+
20
+ def stop
21
+ ActiveSupport::Notifications.unsubscribe(@subscriber) if @subscriber
22
+ @subscriber = nil
23
+ end
24
+
25
+ def broadcast(entry)
26
+ @schema.subscriptions.trigger(
27
+ "audit_log_entry_created",
28
+ {item_type: entry.item_type, item_id: entry.item_id.to_s},
29
+ entry
30
+ )
31
+
32
+ return unless entry.actor_id.present?
33
+
34
+ @schema.subscriptions.trigger(
35
+ "audit_log_entry_created",
36
+ {actor_id: entry.actor_id.to_s},
37
+ entry
38
+ )
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAuditLog
4
+ module Graphql
5
+ module Types
6
+ class BaseSubscription < GraphQL::Schema::Subscription
7
+ end
8
+ end
9
+ end
10
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RailsAuditLog
4
4
  module Graphql
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
@@ -3,6 +3,7 @@
3
3
  require "graphql"
4
4
  require_relative "graphql/version"
5
5
  require_relative "graphql/types/base_object"
6
+ require_relative "graphql/types/base_subscription"
6
7
  require_relative "graphql/types/diff_type"
7
8
  require_relative "graphql/types/actor_type"
8
9
  require_relative "graphql/types/audited_resource_type"
@@ -11,6 +12,9 @@ require_relative "graphql/types/sort_direction_enum"
11
12
  require_relative "graphql/types/audit_log_entry_sort_field_enum"
12
13
  require_relative "graphql/input_objects/audit_log_entry_sort_input"
13
14
  require_relative "graphql/queries/audit_log_entries_query_mixin"
15
+ require_relative "graphql/subscriptions/audit_log_entry_created"
16
+ require_relative "graphql/subscriptions/audit_log_subscriptions_mixin"
17
+ require_relative "graphql/subscriptions/broadcaster"
14
18
 
15
19
  module RailsAuditLog
16
20
  module Graphql
@@ -6,6 +6,9 @@ module RailsAuditLog
6
6
  class BaseObject < GraphQL::Schema::Object
7
7
  end
8
8
 
9
+ class BaseSubscription < GraphQL::Schema::Subscription
10
+ end
11
+
9
12
  class DiffType < BaseObject
10
13
  def attribute: () -> String
11
14
  def from: () -> untyped
@@ -51,6 +54,24 @@ module RailsAuditLog
51
54
  end
52
55
  end
53
56
 
57
+ module Subscriptions
58
+ class AuditLogEntryCreated < Types::BaseSubscription
59
+ def subscribe: (?item_type: String?, ?item_id: String?, ?actor_id: String?) -> :no_response
60
+ def update: (?item_type: String?, ?item_id: String?, ?actor_id: String?) -> untyped
61
+ end
62
+
63
+ module AuditLogSubscriptionsMixin
64
+ def self.included: (untyped base) -> void
65
+ end
66
+
67
+ class Broadcaster
68
+ def initialize: (schema: untyped) -> void
69
+ def start: () -> void
70
+ def stop: () -> void
71
+ def broadcast: (untyped entry) -> void
72
+ end
73
+ end
74
+
54
75
  module Queries
55
76
  module AuditLogEntriesQueryMixin
56
77
  def self.included: (untyped base) -> void
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_audit_log-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuck Smith
@@ -86,11 +86,15 @@ files:
86
86
  - lib/rails_audit_log/graphql/input_objects/audit_log_entry_sort_input.rb
87
87
  - lib/rails_audit_log/graphql/queries/audit_log_entries_query_mixin.rb
88
88
  - lib/rails_audit_log/graphql/release_tooling.rb
89
+ - lib/rails_audit_log/graphql/subscriptions/audit_log_entry_created.rb
90
+ - lib/rails_audit_log/graphql/subscriptions/audit_log_subscriptions_mixin.rb
91
+ - lib/rails_audit_log/graphql/subscriptions/broadcaster.rb
89
92
  - lib/rails_audit_log/graphql/types/actor_type.rb
90
93
  - lib/rails_audit_log/graphql/types/audit_log_entry_sort_field_enum.rb
91
94
  - lib/rails_audit_log/graphql/types/audit_log_entry_type.rb
92
95
  - lib/rails_audit_log/graphql/types/audited_resource_type.rb
93
96
  - lib/rails_audit_log/graphql/types/base_object.rb
97
+ - lib/rails_audit_log/graphql/types/base_subscription.rb
94
98
  - lib/rails_audit_log/graphql/types/diff_type.rb
95
99
  - lib/rails_audit_log/graphql/types/sort_direction_enum.rb
96
100
  - lib/rails_audit_log/graphql/version.rb