rails_audit_log-graphql 0.1.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 +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +107 -0
- data/ROADMAP.md +0 -17
- data/Rakefile +2 -0
- data/lib/rails_audit_log/graphql/input_objects/audit_log_entry_sort_input.rb +15 -0
- data/lib/rails_audit_log/graphql/queries/audit_log_entries_query_mixin.rb +44 -5
- data/lib/rails_audit_log/graphql/types/actor_type.rb +23 -0
- data/lib/rails_audit_log/graphql/types/audit_log_entry_sort_field_enum.rb +14 -0
- data/lib/rails_audit_log/graphql/types/audit_log_entry_type.rb +21 -0
- data/lib/rails_audit_log/graphql/types/audited_resource_type.rb +23 -0
- data/lib/rails_audit_log/graphql/types/diff_type.rb +28 -0
- data/lib/rails_audit_log/graphql/types/sort_direction_enum.rb +15 -0
- data/lib/rails_audit_log/graphql/version.rb +1 -1
- data/lib/rails_audit_log/graphql.rb +6 -0
- data/sig/rails_audit_log/graphql.rbs +71 -2
- metadata +7 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8365cc8fe6ee9823f9cc1ec386fe119675e60fb70214e4fd91e3133c4b1c208
|
|
4
|
+
data.tar.gz: 89251a109b0d83c5150fd3b93253a8152421c9eb5bb2ef6ddc2be7304761e451
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dc978f7e8627a1f0449ee93e0abe737eb1e4a5b348d66295fb9630a5714553ea2b4d594a69e55fc682724fbc689493592ad656b217cb17f5150614746416224c
|
|
7
|
+
data.tar.gz: b93fdc0c1577144640b5475c7af57407827ffe015d3579aa2d4fd2c1d3b58ccd5b31c891b66790a9c75e745eb4b5c674172d79c0fdd9c3a2dc8a26caa3b00356
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
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
|
+
|
|
11
|
+
## [0.2.0] - 2026-06-03
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `auditLogEntriesConnection` — new Relay-style cursor-paginated field returning `AuditLogEntryConnection!` with `nodes`, `edges`, `pageInfo`, and `first`/`after`/`last`/`before` arguments; accepts the same filters as `auditLogEntries`
|
|
16
|
+
- `since:` and `until:` (`ISO8601DateTime`) arguments on both `auditLogEntries` and `auditLogEntriesConnection` for filtering by creation time range
|
|
17
|
+
- `touching:` (`String`) argument on both `auditLogEntries` and `auditLogEntriesConnection` — filters to entries whose `object_changes` include the named attribute
|
|
18
|
+
- `orderBy:` (`AuditLogEntrySortInput`) argument on both `auditLogEntries` and `auditLogEntriesConnection` — accepts `{ field: CREATED_AT, direction: ASC | DESC }`; defaults to `CREATED_AT DESC`
|
|
19
|
+
- `AuditLogEntrySortInput` input object type, `AuditLogEntrySortField` enum, and `SortDirection` enum added to the schema
|
|
20
|
+
|
|
3
21
|
## [0.1.0] - 2026-06-03
|
|
4
22
|
|
|
5
23
|
### 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,11 +144,63 @@ 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
|
|
|
154
|
+
Results default to `created_at DESC` ordering.
|
|
155
|
+
|
|
156
|
+
#### `auditLogEntriesConnection(...): AuditLogEntryConnection!`
|
|
157
|
+
|
|
158
|
+
Same filters as `auditLogEntries`, but returns a [Relay-style connection](https://relay.dev/graphql/connections.htm) for cursor-based pagination.
|
|
159
|
+
|
|
160
|
+
| Argument | Type | Description |
|
|
161
|
+
|---|---|---|
|
|
162
|
+
| `event` | `String` | Filter by event type (`create`, `update`, `destroy`) |
|
|
163
|
+
| `itemType` | `String` | Filter by audited model class name |
|
|
164
|
+
| `itemId` | `ID` | Filter by audited record ID |
|
|
165
|
+
| `actorId` | `ID` | Filter by actor ID |
|
|
166
|
+
| `first` | `Int` | Return the first N edges after `after` |
|
|
167
|
+
| `after` | `String` | Cursor to paginate forward from |
|
|
168
|
+
| `last` | `Int` | Return the last N edges before `before` |
|
|
169
|
+
| `before` | `String` | Cursor to paginate backward from |
|
|
170
|
+
|
|
95
171
|
Results are ordered by `created_at DESC`.
|
|
96
172
|
|
|
173
|
+
**Example — first page:**
|
|
174
|
+
|
|
175
|
+
```graphql
|
|
176
|
+
{
|
|
177
|
+
auditLogEntriesConnection(first: 25) {
|
|
178
|
+
nodes {
|
|
179
|
+
id
|
|
180
|
+
event
|
|
181
|
+
itemType
|
|
182
|
+
itemId
|
|
183
|
+
createdAt
|
|
184
|
+
}
|
|
185
|
+
pageInfo {
|
|
186
|
+
hasNextPage
|
|
187
|
+
endCursor
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**Example — next page using a cursor:**
|
|
194
|
+
|
|
195
|
+
```graphql
|
|
196
|
+
{
|
|
197
|
+
auditLogEntriesConnection(first: 25, after: "eyJpZCI6NDJ9") {
|
|
198
|
+
nodes { id event }
|
|
199
|
+
pageInfo { hasNextPage endCursor }
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
97
204
|
[↑ Back to top](#table-of-contents)
|
|
98
205
|
|
|
99
206
|
### Authentication
|
data/ROADMAP.md
CHANGED
|
@@ -4,23 +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.2.0 — Filtering & Connections
|
|
8
|
-
|
|
9
|
-
- **Time-range filters** — `since:` and `until:` arguments on `auditLogEntries`
|
|
10
|
-
- **`touching:` filter** — narrow results to entries that changed a specific attribute
|
|
11
|
-
- **Relay-style connection** — replace offset pagination with cursor-based `AuditLogEntryConnection` for forward/backward pagination
|
|
12
|
-
- **Sorting** — `orderBy: { field: CREATED_AT, direction: DESC }`
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
## 0.3.0 — Actor & Resource Resolver Types
|
|
17
|
-
|
|
18
|
-
- **`ActorType`** — resolve the polymorphic `actor` to the concrete type in the host app's schema (requires a configurable type resolver proc)
|
|
19
|
-
- **`AuditedResourceType`** — resolve `item_type`/`item_id` to the concrete audited model type
|
|
20
|
-
- **`diffType`** — structured `{ from, to }` diff type instead of raw `objectChanges` JSON
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
7
|
## 0.4.0 — Subscriptions
|
|
25
8
|
|
|
26
9
|
Requires Action Cable in the host application.
|
data/Rakefile
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsAuditLog
|
|
4
|
+
module Graphql
|
|
5
|
+
module InputObjects
|
|
6
|
+
class AuditLogEntrySortInput < GraphQL::Schema::InputObject
|
|
7
|
+
graphql_name "AuditLogEntrySortInput"
|
|
8
|
+
description "Sort order for audit log entry queries."
|
|
9
|
+
|
|
10
|
+
argument :field, Types::AuditLogEntrySortFieldEnum, required: true, description: "Field to sort by."
|
|
11
|
+
argument :direction, Types::SortDirectionEnum, required: true, description: "Sort direction (ASC or DESC)."
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -27,9 +27,30 @@ module RailsAuditLog
|
|
|
27
27
|
argument :item_type, String, required: false, description: "Filter by audited model class name."
|
|
28
28
|
argument :item_id, GraphQL::Types::ID, required: false, description: "Filter by audited record ID."
|
|
29
29
|
argument :actor_id, GraphQL::Types::ID, required: false, description: "Filter by actor ID."
|
|
30
|
+
argument :since, GraphQL::Types::ISO8601DateTime, required: false, description: "Return entries created at or after this time."
|
|
31
|
+
argument :until, GraphQL::Types::ISO8601DateTime, required: false, as: :until_time, description: "Return entries created at or before this time."
|
|
32
|
+
argument :touching, String, required: false, description: "Filter to entries that changed a specific attribute (matches object_changes keys)."
|
|
33
|
+
argument :order_by, RailsAuditLog::Graphql::InputObjects::AuditLogEntrySortInput, required: false, description: "Sort order. Defaults to CREATED_AT DESC."
|
|
30
34
|
argument :page, GraphQL::Types::Int, required: false, default_value: 1, description: "Page number (1-based)."
|
|
31
35
|
argument :per_page, GraphQL::Types::Int, required: false, default_value: 25, description: "Number of results per page."
|
|
32
36
|
end
|
|
37
|
+
|
|
38
|
+
base.field(
|
|
39
|
+
:audit_log_entries_connection,
|
|
40
|
+
RailsAuditLog::Graphql::Types::AuditLogEntryType.connection_type,
|
|
41
|
+
null: false,
|
|
42
|
+
description: "List audit log entries with optional filters. Cursor-paginated (Relay connection).",
|
|
43
|
+
resolver_method: :resolve_audit_log_entries_connection
|
|
44
|
+
) do
|
|
45
|
+
argument :event, String, required: false, description: "Filter by event type (create, update, destroy)."
|
|
46
|
+
argument :item_type, String, required: false, description: "Filter by audited model class name."
|
|
47
|
+
argument :item_id, GraphQL::Types::ID, required: false, description: "Filter by audited record ID."
|
|
48
|
+
argument :actor_id, GraphQL::Types::ID, required: false, description: "Filter by actor ID."
|
|
49
|
+
argument :since, GraphQL::Types::ISO8601DateTime, required: false, description: "Return entries created at or after this time."
|
|
50
|
+
argument :until, GraphQL::Types::ISO8601DateTime, required: false, as: :until_time, description: "Return entries created at or before this time."
|
|
51
|
+
argument :touching, String, required: false, description: "Filter to entries that changed a specific attribute (matches object_changes keys)."
|
|
52
|
+
argument :order_by, RailsAuditLog::Graphql::InputObjects::AuditLogEntrySortInput, required: false, description: "Sort order. Defaults to CREATED_AT DESC."
|
|
53
|
+
end
|
|
33
54
|
end
|
|
34
55
|
|
|
35
56
|
def resolve_audit_log_entry(id:)
|
|
@@ -37,18 +58,36 @@ module RailsAuditLog
|
|
|
37
58
|
RailsAuditLog::AuditLogEntry.find_by(id: id)
|
|
38
59
|
end
|
|
39
60
|
|
|
40
|
-
def resolve_audit_log_entries(event: nil, item_type: nil, item_id: nil, actor_id: nil, page: 1, per_page: 25)
|
|
61
|
+
def resolve_audit_log_entries(event: nil, item_type: nil, item_id: nil, actor_id: nil, since: nil, until_time: nil, touching: nil, order_by: nil, page: 1, per_page: 25)
|
|
41
62
|
check_authentication!
|
|
42
|
-
scope =
|
|
63
|
+
scope = build_scope(event: event, item_type: item_type, item_id: item_id, actor_id: actor_id, since: since, until_time: until_time, touching: touching, order_by: order_by)
|
|
64
|
+
scope.limit(per_page).offset((page - 1) * per_page)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def resolve_audit_log_entries_connection(event: nil, item_type: nil, item_id: nil, actor_id: nil, since: nil, until_time: nil, touching: nil, order_by: nil)
|
|
68
|
+
check_authentication!
|
|
69
|
+
build_scope(event: event, item_type: item_type, item_id: item_id, actor_id: actor_id, since: since, until_time: until_time, touching: touching, order_by: order_by)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
def build_scope(event: nil, item_type: nil, item_id: nil, actor_id: nil, since: nil, until_time: nil, touching: nil, order_by: nil)
|
|
75
|
+
sort_field = order_by&.field || :created_at
|
|
76
|
+
sort_direction = order_by&.direction || :desc
|
|
77
|
+
scope = RailsAuditLog::AuditLogEntry.order(sort_field => sort_direction)
|
|
43
78
|
scope = scope.where(event: event) if event
|
|
44
79
|
scope = scope.where(item_type: item_type) if item_type
|
|
45
80
|
scope = scope.where(item_id: item_id) if item_id
|
|
46
81
|
scope = scope.where(actor_id: actor_id) if actor_id
|
|
47
|
-
scope.
|
|
82
|
+
scope = scope.where("created_at >= ?", since) if since
|
|
83
|
+
scope = scope.where("created_at <= ?", until_time) if until_time
|
|
84
|
+
if touching
|
|
85
|
+
safe = ActiveRecord::Base.sanitize_sql_like(touching)
|
|
86
|
+
scope = scope.where("object_changes LIKE ?", "%\"#{safe}\":%")
|
|
87
|
+
end
|
|
88
|
+
scope
|
|
48
89
|
end
|
|
49
90
|
|
|
50
|
-
private
|
|
51
|
-
|
|
52
91
|
def check_authentication!
|
|
53
92
|
auth = RailsAuditLog.authenticate
|
|
54
93
|
return unless auth
|
|
@@ -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
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsAuditLog
|
|
4
|
+
module Graphql
|
|
5
|
+
module Types
|
|
6
|
+
class AuditLogEntrySortFieldEnum < GraphQL::Schema::Enum
|
|
7
|
+
graphql_name "AuditLogEntrySortField"
|
|
8
|
+
description "Fields available for sorting audit log entries."
|
|
9
|
+
|
|
10
|
+
value "CREATED_AT", value: :created_at, description: "Sort by creation time."
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
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
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsAuditLog
|
|
4
|
+
module Graphql
|
|
5
|
+
module Types
|
|
6
|
+
class SortDirectionEnum < GraphQL::Schema::Enum
|
|
7
|
+
graphql_name "SortDirection"
|
|
8
|
+
description "Sort direction for ordered queries."
|
|
9
|
+
|
|
10
|
+
value "ASC", value: :asc, description: "Ascending order."
|
|
11
|
+
value "DESC", value: :desc, description: "Descending order."
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -3,7 +3,13 @@
|
|
|
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"
|
|
10
|
+
require_relative "graphql/types/sort_direction_enum"
|
|
11
|
+
require_relative "graphql/types/audit_log_entry_sort_field_enum"
|
|
12
|
+
require_relative "graphql/input_objects/audit_log_entry_sort_input"
|
|
7
13
|
require_relative "graphql/queries/audit_log_entries_query_mixin"
|
|
8
14
|
|
|
9
15
|
module RailsAuditLog
|
|
@@ -6,7 +6,39 @@ 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]]?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class SortDirectionEnum < GraphQL::Schema::Enum
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class AuditLogEntrySortFieldEnum < GraphQL::Schema::Enum
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
module InputObjects
|
|
39
|
+
class AuditLogEntrySortInput < GraphQL::Schema::InputObject
|
|
40
|
+
def field: () -> Symbol
|
|
41
|
+
def direction: () -> Symbol
|
|
10
42
|
end
|
|
11
43
|
end
|
|
12
44
|
|
|
@@ -22,11 +54,48 @@ module RailsAuditLog
|
|
|
22
54
|
module Queries
|
|
23
55
|
module AuditLogEntriesQueryMixin
|
|
24
56
|
def self.included: (untyped base) -> void
|
|
57
|
+
|
|
25
58
|
def resolve_audit_log_entry: (id: String) -> untyped
|
|
26
|
-
|
|
59
|
+
|
|
60
|
+
def resolve_audit_log_entries: (
|
|
61
|
+
?event: String?,
|
|
62
|
+
?item_type: String?,
|
|
63
|
+
?item_id: String?,
|
|
64
|
+
?actor_id: String?,
|
|
65
|
+
?since: Time?,
|
|
66
|
+
?until_time: Time?,
|
|
67
|
+
?touching: String?,
|
|
68
|
+
?order_by: InputObjects::AuditLogEntrySortInput?,
|
|
69
|
+
?page: Integer,
|
|
70
|
+
?per_page: Integer
|
|
71
|
+
) -> untyped
|
|
72
|
+
|
|
73
|
+
def resolve_audit_log_entries_connection: (
|
|
74
|
+
?event: String?,
|
|
75
|
+
?item_type: String?,
|
|
76
|
+
?item_id: String?,
|
|
77
|
+
?actor_id: String?,
|
|
78
|
+
?since: Time?,
|
|
79
|
+
?until_time: Time?,
|
|
80
|
+
?touching: String?,
|
|
81
|
+
?order_by: InputObjects::AuditLogEntrySortInput?
|
|
82
|
+
) -> untyped
|
|
83
|
+
|
|
27
84
|
private
|
|
85
|
+
|
|
86
|
+
def build_scope: (
|
|
87
|
+
?event: String?,
|
|
88
|
+
?item_type: String?,
|
|
89
|
+
?item_id: String?,
|
|
90
|
+
?actor_id: String?,
|
|
91
|
+
?since: Time?,
|
|
92
|
+
?until_time: Time?,
|
|
93
|
+
?touching: String?,
|
|
94
|
+
?order_by: InputObjects::AuditLogEntrySortInput?
|
|
95
|
+
) -> untyped
|
|
96
|
+
|
|
28
97
|
def check_authentication!: () -> void
|
|
29
98
|
end
|
|
30
99
|
end
|
|
31
100
|
end
|
|
32
|
-
end
|
|
101
|
+
end
|
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.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chuck Smith
|
|
@@ -83,10 +83,16 @@ files:
|
|
|
83
83
|
- codecov.yml
|
|
84
84
|
- lib/generators/rails_audit_log/graphql/install/install_generator.rb
|
|
85
85
|
- lib/rails_audit_log/graphql.rb
|
|
86
|
+
- lib/rails_audit_log/graphql/input_objects/audit_log_entry_sort_input.rb
|
|
86
87
|
- lib/rails_audit_log/graphql/queries/audit_log_entries_query_mixin.rb
|
|
87
88
|
- lib/rails_audit_log/graphql/release_tooling.rb
|
|
89
|
+
- lib/rails_audit_log/graphql/types/actor_type.rb
|
|
90
|
+
- lib/rails_audit_log/graphql/types/audit_log_entry_sort_field_enum.rb
|
|
88
91
|
- lib/rails_audit_log/graphql/types/audit_log_entry_type.rb
|
|
92
|
+
- lib/rails_audit_log/graphql/types/audited_resource_type.rb
|
|
89
93
|
- lib/rails_audit_log/graphql/types/base_object.rb
|
|
94
|
+
- lib/rails_audit_log/graphql/types/diff_type.rb
|
|
95
|
+
- lib/rails_audit_log/graphql/types/sort_direction_enum.rb
|
|
90
96
|
- lib/rails_audit_log/graphql/version.rb
|
|
91
97
|
- sig/rails_audit_log/graphql.rbs
|
|
92
98
|
homepage: https://github.com/eclectic-coding/rails_audit_log-graphql
|