graphiti 2.2.0 → 2.2.1
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 +7 -0
- data/lib/graphiti/resource/persistence.rb +0 -2
- data/lib/graphiti/util/persistence.rb +15 -5
- data/lib/graphiti/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 30c83060dec6dbefde24170e461c2d2a82447ef77f050acf78cfd3a9dd46b1e6
|
|
4
|
+
data.tar.gz: 16bb19c4b54461098992d5a318e812bcf74f1b6a2cb49683a43d61f888599426
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: df3aa94529b3e261db005cb09533a3edb838c26187daac12863dcc2d71e2663b43f2784a58bace69c60781e97de42dd2a087b4a87159559cd9ba64d7b61cb055
|
|
7
|
+
data.tar.gz: bce4cb95504b17925469722ec53669c9ac0126ebc1b507b00ea65829f7b9ce3294f9123b6558fa7cd9f1aaaadedca7c1de4720a5014da20a52136c2ab6c7e1a6
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
graphiti changelog
|
|
2
2
|
|
|
3
|
+
## [2.2.1](https://github.com/graphiti-api/graphiti/compare/v2.2.0...v2.2.1) (2026-10-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* a create or update override receives decoded foreign keys, not the public ids the client posted ([971d144](https://github.com/graphiti-api/graphiti/commit/971d144a323625b5d1b03f6e4ab551a4dfee12c4))
|
|
9
|
+
|
|
3
10
|
# [2.2.0](https://github.com/graphiti-api/graphiti/compare/v2.1.3...v2.2.0) (2026-10-13)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -86,8 +86,6 @@ module Graphiti
|
|
|
86
86
|
assign_params = assign_params.except(:id).merge(self.class.model_primary_key => primary_key)
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
assign_params = decode_foreign_keys(assign_params)
|
|
90
|
-
|
|
91
89
|
run_callbacks :attributes, action_name, assign_params, meta do |params|
|
|
92
90
|
model_instance ||= if action_name == :update
|
|
93
91
|
self.class._find(id: id).data
|
|
@@ -29,7 +29,7 @@ class Graphiti::Util::Persistence
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def assign
|
|
32
|
-
attributes = @adapter.persistence_attributes(self, @attributes)
|
|
32
|
+
attributes = decode_foreign_keys(@adapter.persistence_attributes(self, @attributes))
|
|
33
33
|
assigned = @resource.assign(attributes, metadata, @meta[:method], model_instance: @assigned_model)
|
|
34
34
|
@resource.decorate_record(assigned)
|
|
35
35
|
|
|
@@ -60,7 +60,9 @@ class Graphiti::Util::Persistence
|
|
|
60
60
|
|
|
61
61
|
payload_attributes = attributes.dup
|
|
62
62
|
parents = @adapter.process_belongs_to(self, attributes)
|
|
63
|
-
|
|
63
|
+
derived_keys = derived_keys(attributes, payload_attributes)
|
|
64
|
+
attributes = decode_foreign_keys(attributes)
|
|
65
|
+
apply_derived_attributes(attributes.slice(*derived_keys))
|
|
64
66
|
persisted = persist_object(@meta[:method], attributes)
|
|
65
67
|
@resource.decorate_record(persisted)
|
|
66
68
|
|
|
@@ -99,15 +101,23 @@ class Graphiti::Util::Persistence
|
|
|
99
101
|
# +attributes+. A model that was already assigned (see ResourceProxy#assign_attributes)
|
|
100
102
|
# predates those keys, so apply just them - the payload attributes are already on it,
|
|
101
103
|
# and re-applying them would clobber any changes made since.
|
|
102
|
-
def apply_derived_attributes(
|
|
104
|
+
def apply_derived_attributes(derived)
|
|
103
105
|
return unless @assigned_model
|
|
104
|
-
|
|
105
|
-
derived = @resource.decode_foreign_keys(attributes).reject { |key, value| payload_attributes[key] == value }
|
|
106
106
|
return if derived.empty?
|
|
107
107
|
|
|
108
108
|
@resource.assign_attributes(@assigned_model, derived, metadata)
|
|
109
109
|
end
|
|
110
110
|
|
|
111
|
+
def derived_keys(attributes, payload_attributes)
|
|
112
|
+
attributes.keys.reject { |key| payload_attributes.key?(key) && payload_attributes[key] == attributes[key] }
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def decode_foreign_keys(attributes)
|
|
116
|
+
return attributes if @meta[:method] == :destroy
|
|
117
|
+
|
|
118
|
+
@resource.decode_foreign_keys(attributes)
|
|
119
|
+
end
|
|
120
|
+
|
|
111
121
|
def add_hook(prc, lifecycle_event)
|
|
112
122
|
::Graphiti::Util::TransactionHooksRecorder.add(prc, lifecycle_event)
|
|
113
123
|
end
|
data/lib/graphiti/version.rb
CHANGED