rails_audit_log-graphql 0.2.0 → 0.3.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: 6c89d640d69c533ded27f477ed99b03275c34b4564c90e6eaccfe86a131f2447
4
- data.tar.gz: d34b732d907a2db6b9c6c0bfba266933aaf6f21be9c8770caa8c64b50a81c870
3
+ metadata.gz: e8365cc8fe6ee9823f9cc1ec386fe119675e60fb70214e4fd91e3133c4b1c208
4
+ data.tar.gz: 89251a109b0d83c5150fd3b93253a8152421c9eb5bb2ef6ddc2be7304761e451
5
5
  SHA512:
6
- metadata.gz: faa1b363d2aaebc1b3f5573f0b6c757a5d6b4d1fe8b6a1af7d906bd9877f23cecf897b75640b9f61e24e622d06c4233825be5047bada0d92371f954749a2499f
7
- data.tar.gz: '08c32d0f02192b6db82d11e414ac04beb42a54ce61bb6dd8b025b2866f1569bc65b7b177ba308a4c0d241d7486029741e03abf082af38726fa2bbd30d6d2c6f4'
6
+ metadata.gz: dc978f7e8627a1f0449ee93e0abe737eb1e4a5b348d66295fb9630a5714553ea2b4d594a69e55fc682724fbc689493592ad656b217cb17f5150614746416224c
7
+ data.tar.gz: b93fdc0c1577144640b5475c7af57407827ffe015d3579aa2d4fd2c1d3b58ccd5b31c891b66790a9c75e745eb4b5c674172d79c0fdd9c3a2dc8a26caa3b00356
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2026-06-03
4
+
5
+ ### Added
6
+
7
+ - `ActorType` (`AuditLogActor`) — new object type with `id` and `typeName` fields exposing the polymorphic actor reference; adds `actor: AuditLogActor` field on `AuditLogEntry`
8
+ - `AuditedResourceType` (`AuditedResource`) — new object type with `id` and `typeName` fields exposing the audited model reference; adds `auditedResource: AuditedResource!` field on `AuditLogEntry`
9
+ - `DiffType` (`AuditLogDiff`) — new object type with `attribute`, `from`, and `to` fields; adds `diff: [AuditLogDiff!]` field on `AuditLogEntry` parsed from `objectChanges`
10
+
3
11
  ## [0.2.0] - 2026-06-03
4
12
 
5
13
  ### Added
data/README.md CHANGED
@@ -13,9 +13,13 @@ A [graphql-ruby](https://graphql-ruby.org) API layer for the [`rails_audit_log`]
13
13
  - [Installation](#installation)
14
14
  - [Usage](#usage)
15
15
  - [AuditLogEntryType](#auditlogentrytype)
16
+ - [AuditLogActor](#auditlogactor)
17
+ - [AuditedResource](#auditedresource)
18
+ - [AuditLogDiff](#auditlogdiff)
16
19
  - [AuditLogEntriesQueryMixin](#auditlogentriesquerymixin)
17
20
  - [auditLogEntry](#auditlogentryid-id-auditlogentry)
18
21
  - [auditLogEntries](#auditlogentries-auditlogentry)
22
+ - [auditLogEntriesConnection](#auditlogentriesconnection-auditlogentryconnection)
19
23
  - [Authentication](#authentication)
20
24
  - [Development](#development)
21
25
  - [Contributing](#contributing)
@@ -61,6 +65,57 @@ This injects `include RailsAuditLog::Graphql::Queries::AuditLogEntriesQueryMixin
61
65
  | `actorType` | `String` | yes |
62
66
  | `actorId` | `ID` | yes |
63
67
  | `tenantId` | `String` | yes |
68
+ | `actor` | `AuditLogActor` | yes |
69
+ | `auditedResource` | `AuditedResource` | no |
70
+ | `diff` | `[AuditLogDiff!]` | yes |
71
+
72
+ [↑ Back to top](#table-of-contents)
73
+
74
+ ### AuditLogActor
75
+
76
+ `RailsAuditLog::Graphql::Types::ActorType` — a polymorphic reference to the actor who performed the audited action. Returned by the `actor` field on `AuditLogEntry`. `null` when no actor was recorded.
77
+
78
+ | GraphQL field | Type | Nullable |
79
+ |---|---|---|
80
+ | `id` | `ID` | no |
81
+ | `typeName` | `String` | no |
82
+
83
+ [↑ Back to top](#table-of-contents)
84
+
85
+ ### AuditedResource
86
+
87
+ `RailsAuditLog::Graphql::Types::AuditedResourceType` — a reference to the model record that was changed. Returned by the `auditedResource` field on `AuditLogEntry`. Always present.
88
+
89
+ | GraphQL field | Type | Nullable |
90
+ |---|---|---|
91
+ | `id` | `ID` | no |
92
+ | `typeName` | `String` | no |
93
+
94
+ [↑ Back to top](#table-of-contents)
95
+
96
+ ### AuditLogDiff
97
+
98
+ `RailsAuditLog::Graphql::Types::DiffType` — a single attribute change parsed from `objectChanges`. Returned as a list by the `diff` field on `AuditLogEntry`. `null` when `objectChanges` is not recorded (e.g. destroy events).
99
+
100
+ | GraphQL field | Type | Nullable | Description |
101
+ |---|---|---|---|
102
+ | `attribute` | `String` | no | Name of the changed attribute |
103
+ | `from` | `JSON` | yes | Value before the change |
104
+ | `to` | `JSON` | yes | Value after the change |
105
+
106
+ **Example:**
107
+
108
+ ```graphql
109
+ {
110
+ auditLogEntries(event: "update") {
111
+ diff {
112
+ attribute
113
+ from
114
+ to
115
+ }
116
+ }
117
+ }
118
+ ```
64
119
 
65
120
  [↑ Back to top](#table-of-contents)
66
121
 
@@ -89,10 +144,14 @@ List entries with optional filters and offset pagination.
89
144
  | `itemType` | `String` | — | Filter by audited model class name |
90
145
  | `itemId` | `ID` | — | Filter by audited record ID |
91
146
  | `actorId` | `ID` | — | Filter by actor ID |
147
+ | `since` | `ISO8601DateTime` | — | Return entries created at or after this time |
148
+ | `until` | `ISO8601DateTime` | — | Return entries created at or before this time |
149
+ | `touching` | `String` | — | Filter to entries that changed a specific attribute |
150
+ | `orderBy` | `AuditLogEntrySortInput` | `CREATED_AT DESC` | Sort field and direction |
92
151
  | `page` | `Int` | `1` | Page number (1-based) |
93
152
  | `perPage` | `Int` | `25` | Results per page |
94
153
 
95
- Results are ordered by `created_at DESC`.
154
+ Results default to `created_at DESC` ordering.
96
155
 
97
156
  #### `auditLogEntriesConnection(...): AuditLogEntryConnection!`
98
157
 
data/ROADMAP.md CHANGED
@@ -4,14 +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.3.0 — Actor & Resource Resolver Types
8
-
9
- - **`ActorType`** — resolve the polymorphic `actor` to the concrete type in the host app's schema (requires a configurable type resolver proc)
10
- - **`AuditedResourceType`** — resolve `item_type`/`item_id` to the concrete audited model type
11
- - **`diffType`** — structured `{ from, to }` diff type instead of raw `objectChanges` JSON
12
-
13
- ---
14
-
15
7
  ## 0.4.0 — Subscriptions
16
8
 
17
9
  Requires Action Cable in the host application.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAuditLog
4
+ module Graphql
5
+ module Types
6
+ class ActorType < BaseObject
7
+ graphql_name "AuditLogActor"
8
+ description "A polymorphic reference to the actor who performed the audited action."
9
+
10
+ field :id, GraphQL::Types::ID, null: false, description: "The actor's ID."
11
+ field :type_name, String, null: false, description: "The actor's model class name (e.g. \"User\")."
12
+
13
+ def id
14
+ object[:id]
15
+ end
16
+
17
+ def type_name
18
+ object[:type_name]
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -20,6 +20,27 @@ module RailsAuditLog
20
20
  field :actor_id, GraphQL::Types::ID, null: true
21
21
  field :tenant_id, String, null: true
22
22
  field :created_at, GraphQL::Types::ISO8601DateTime, null: false
23
+ field :actor, Types::ActorType, null: true,
24
+ description: "The actor who performed this action, as a polymorphic reference."
25
+ field :audited_resource, Types::AuditedResourceType, null: false,
26
+ description: "The model type and ID of the record that was changed."
27
+ field :diff, [Types::DiffType, null: false], null: true,
28
+ description: "Structured per-attribute diffs parsed from objectChanges. Nil when no changes are recorded."
29
+
30
+ def actor
31
+ return nil if object.actor_id.nil? || object.actor_type.nil?
32
+ {id: object.actor_id, type_name: object.actor_type}
33
+ end
34
+
35
+ def audited_resource
36
+ {id: object.item_id, type_name: object.item_type}
37
+ end
38
+
39
+ def diff
40
+ changes = object.object_changes
41
+ return nil if changes.nil?
42
+ changes.map { |attr, (from_val, to_val)| {attribute: attr, from: from_val, to: to_val} }
43
+ end
23
44
  end
24
45
  end
25
46
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAuditLog
4
+ module Graphql
5
+ module Types
6
+ class AuditedResourceType < BaseObject
7
+ graphql_name "AuditedResource"
8
+ description "A reference to the model record that was changed."
9
+
10
+ field :id, GraphQL::Types::ID, null: false, description: "The audited record's ID."
11
+ field :type_name, String, null: false, description: "The audited model class name (e.g. \"Post\")."
12
+
13
+ def id
14
+ object[:id]
15
+ end
16
+
17
+ def type_name
18
+ object[:type_name]
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAuditLog
4
+ module Graphql
5
+ module Types
6
+ class DiffType < BaseObject
7
+ graphql_name "AuditLogDiff"
8
+ description "A single attribute change with before and after values."
9
+
10
+ field :attribute, String, null: false, description: "The name of the changed attribute."
11
+ field :from, GraphQL::Types::JSON, null: true, description: "Value before the change."
12
+ field :to, GraphQL::Types::JSON, null: true, description: "Value after the change."
13
+
14
+ def attribute
15
+ object[:attribute]
16
+ end
17
+
18
+ def from
19
+ object[:from]
20
+ end
21
+
22
+ def to
23
+ object[:to]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RailsAuditLog
4
4
  module Graphql
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -3,6 +3,9 @@
3
3
  require "graphql"
4
4
  require_relative "graphql/version"
5
5
  require_relative "graphql/types/base_object"
6
+ require_relative "graphql/types/diff_type"
7
+ require_relative "graphql/types/actor_type"
8
+ require_relative "graphql/types/audited_resource_type"
6
9
  require_relative "graphql/types/audit_log_entry_type"
7
10
  require_relative "graphql/types/sort_direction_enum"
8
11
  require_relative "graphql/types/audit_log_entry_sort_field_enum"
@@ -6,7 +6,26 @@ module RailsAuditLog
6
6
  class BaseObject < GraphQL::Schema::Object
7
7
  end
8
8
 
9
+ class DiffType < BaseObject
10
+ def attribute: () -> String
11
+ def from: () -> untyped
12
+ def to: () -> untyped
13
+ end
14
+
15
+ class ActorType < BaseObject
16
+ def id: () -> String
17
+ def type_name: () -> String
18
+ end
19
+
20
+ class AuditedResourceType < BaseObject
21
+ def id: () -> String
22
+ def type_name: () -> String
23
+ end
24
+
9
25
  class AuditLogEntryType < BaseObject
26
+ def actor: () -> Hash[Symbol, untyped]?
27
+ def audited_resource: () -> Hash[Symbol, untyped]
28
+ def diff: () -> Array[Hash[Symbol, untyped]]?
10
29
  end
11
30
 
12
31
  class SortDirectionEnum < GraphQL::Schema::Enum
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuck Smith
@@ -86,9 +86,12 @@ 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/types/actor_type.rb
89
90
  - lib/rails_audit_log/graphql/types/audit_log_entry_sort_field_enum.rb
90
91
  - lib/rails_audit_log/graphql/types/audit_log_entry_type.rb
92
+ - lib/rails_audit_log/graphql/types/audited_resource_type.rb
91
93
  - lib/rails_audit_log/graphql/types/base_object.rb
94
+ - lib/rails_audit_log/graphql/types/diff_type.rb
92
95
  - lib/rails_audit_log/graphql/types/sort_direction_enum.rb
93
96
  - lib/rails_audit_log/graphql/version.rb
94
97
  - sig/rails_audit_log/graphql.rbs