graphql-activerecord 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/models/mutation_helpers/apply_changes.rb +21 -12
- data/lib/graphql/models/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e580775093b61f44e8c119e6cdba9c551877841
|
4
|
+
data.tar.gz: 6d8dfe863f25e8345e1724fcdf636c8d3237712b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20f0318b73f6a2ac455cbe6e00af3560920b2cbc68886d93ae4cf370dc10d6709388399cd63ec64858082b59f26aaae5011a0b9322c94c4d198b5d14f3e361ef
|
7
|
+
data.tar.gz: 49d36558ff541fdf34b060e627d67bd9af2173c8e8597d4784477801819e70b0e8b5a1c492a3850da6e3d9e5bc36f518746661679cbe61235729ac05a4d82e0b
|
@@ -85,14 +85,14 @@ module GraphQL::Models
|
|
85
85
|
find_by = Array.wrap(child_map.find_by).map(&:to_s)
|
86
86
|
|
87
87
|
if find_by.empty?
|
88
|
-
return match_inputs_by_position(model, child_map, next_inputs, changes, associated_models
|
88
|
+
return match_inputs_by_position(model, child_map, next_inputs, changes, associated_models)
|
89
89
|
else
|
90
90
|
return match_inputs_by_fields(model, child_map, next_inputs, changes, associated_models, find_by)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
def self.match_inputs_by_position(model, child_map, next_inputs, changes, associated_models
|
95
|
+
def self.match_inputs_by_position(model, child_map, next_inputs, changes, associated_models)
|
96
96
|
count = [associated_models.length, next_inputs.length].max
|
97
97
|
|
98
98
|
matches = []
|
@@ -118,20 +118,30 @@ module GraphQL::Models
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def self.match_inputs_by_fields(model, child_map, next_inputs, changes, associated_models, find_by)
|
121
|
-
|
122
|
-
|
121
|
+
# Convert the find_by into the field definitions, so that we properly unmap aliased fields
|
122
|
+
find_by_defs = find_by.map { |name| child_map.fields.detect { |f| f[:attribute].to_s == name.to_s } }
|
123
|
+
name_to_attr = find_by_defs.map { |f| [f[:name], f[:attribute].to_s] }.to_h
|
124
|
+
|
125
|
+
indexed_models = associated_models.index_by { |m| m.attributes.slice(*find_by) }
|
126
|
+
|
127
|
+
# Inputs are a little nasty, the keys have to be converted from camelCase back to snake_case
|
128
|
+
indexed_inputs = next_inputs.index_by { |ni| ni.to_h.slice(*name_to_attr.keys) }
|
129
|
+
|
130
|
+
indexed_inputs = indexed_inputs.map do |key, inputs|
|
131
|
+
key = key.map { |name, val| [name_to_attr[name], val] }.to_h
|
132
|
+
[key, inputs]
|
133
|
+
end
|
134
|
+
|
135
|
+
indexed_inputs = indexed_inputs.to_h
|
123
136
|
|
124
137
|
# Match each model to its input. If there is no input for it, mark that the model should be destroyed.
|
125
138
|
matches = []
|
126
139
|
|
127
140
|
# TODO: Support for finding by an ID field, that needs to be untranslated from a Relay ID into a model ID
|
128
141
|
|
129
|
-
|
130
|
-
|
142
|
+
indexed_models.each do |key_attrs, child_model|
|
143
|
+
inputs = indexed_inputs[key_attrs]
|
131
144
|
|
132
|
-
inputs = grouped_inputs[key_attrs]
|
133
|
-
inputs = inputs[0] if inputs
|
134
|
-
|
135
145
|
if inputs.nil?
|
136
146
|
child_model.mark_for_destruction
|
137
147
|
changes.push({ model_instance: child_model, action: :destroy })
|
@@ -141,10 +151,9 @@ module GraphQL::Models
|
|
141
151
|
end
|
142
152
|
|
143
153
|
# Build a new model for each input that doesn't have a model
|
144
|
-
|
145
|
-
|
154
|
+
indexed_inputs.each do |key_attrs, inputs|
|
155
|
+
next if indexed_models.include?(key_attrs)
|
146
156
|
|
147
|
-
next if grouped_models.include?(key_attrs)
|
148
157
|
child_model = associated_models.build
|
149
158
|
changes.push({ model_instance: child_model, action: :create })
|
150
159
|
matches.push({ child_model: child_model, child_inputs: inputs, input_path: next_inputs.index(inputs) })
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Foster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|