graphiti 1.2.21 → 1.2.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphiti/adapters/active_record/many_to_many_sideload.rb +19 -0
- data/lib/graphiti/request_validator.rb +6 -6
- data/lib/graphiti/request_validators/validator.rb +7 -1
- data/lib/graphiti/resource/dsl.rb +1 -0
- data/lib/graphiti/resource_proxy.rb +3 -1
- data/lib/graphiti/runner.rb +1 -2
- data/lib/graphiti/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5f2ffef76f6dd895acddc9a4d2deb374a3d217c94d0c85fd1feb40ecac9f369
|
4
|
+
data.tar.gz: c6ce48631bf54161b0678ac5d16a8e25b49c8259ec1405138559814745569129
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e9d797893dfad771fbfe3400fc66e5830b80e8b029a059fdc12102c904e9d535b004fb08bb4501ce190effdda6f247b476ada10c6f0f6f4d963bcb0c971ab50
|
7
|
+
data.tar.gz: 5a933a0b8174449530858b06081eb09cd181d1d02f37f5befaac0e1f3dd16bf420e2e6e72d2c64a4750fd8ff2eaf3e2e333b59843c01ac613fa0c10e3e02ef0e
|
@@ -8,6 +8,18 @@ class Graphiti::Adapters::ActiveRecord::ManyToManySideload < Graphiti::Sideload:
|
|
8
8
|
foreign_key.keys.first
|
9
9
|
end
|
10
10
|
|
11
|
+
def inverse_filter
|
12
|
+
return @inverse_filter if @inverse_filter
|
13
|
+
|
14
|
+
inferred_name = infer_inverse_association
|
15
|
+
|
16
|
+
if inferred_name
|
17
|
+
"#{inferred_name.to_s.singularize}_id"
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
def belongs_to_many_filter(scope, value)
|
12
24
|
if polymorphic?
|
13
25
|
clauses = value.group_by { |v| v["type"] }.map { |group|
|
@@ -76,4 +88,11 @@ class Graphiti::Adapters::ActiveRecord::ManyToManySideload < Graphiti::Sideload:
|
|
76
88
|
value = through_reflection.foreign_key.to_sym
|
77
89
|
{key => value}
|
78
90
|
end
|
91
|
+
|
92
|
+
def infer_inverse_association
|
93
|
+
through_class = through_reflection.klass
|
94
|
+
|
95
|
+
foreign_reflection = through_class.reflections[name.to_s.singularize]
|
96
|
+
foreign_reflection && foreign_reflection.options[:inverse_of]
|
97
|
+
end
|
79
98
|
end
|
@@ -6,18 +6,18 @@ module Graphiti
|
|
6
6
|
:deserialized_payload,
|
7
7
|
to: :@validator
|
8
8
|
|
9
|
-
def initialize(root_resource, raw_params)
|
10
|
-
@validator = ValidatorFactory.create(root_resource, raw_params)
|
9
|
+
def initialize(root_resource, raw_params, action)
|
10
|
+
@validator = ValidatorFactory.create(root_resource, raw_params, action)
|
11
11
|
end
|
12
12
|
|
13
13
|
class ValidatorFactory
|
14
|
-
def self.create(root_resource, raw_params)
|
15
|
-
case
|
16
|
-
when
|
14
|
+
def self.create(root_resource, raw_params, action)
|
15
|
+
case action
|
16
|
+
when :update then
|
17
17
|
RequestValidators::UpdateValidator
|
18
18
|
else
|
19
19
|
RequestValidators::Validator
|
20
|
-
end.new(root_resource, raw_params)
|
20
|
+
end.new(root_resource, raw_params, action)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -3,10 +3,11 @@ module Graphiti
|
|
3
3
|
class Validator
|
4
4
|
attr_reader :errors
|
5
5
|
|
6
|
-
def initialize(root_resource, raw_params)
|
6
|
+
def initialize(root_resource, raw_params, action)
|
7
7
|
@root_resource = root_resource
|
8
8
|
@raw_params = raw_params
|
9
9
|
@errors = Graphiti::Util::SimpleErrors.new(raw_params)
|
10
|
+
@action = action
|
10
11
|
end
|
11
12
|
|
12
13
|
def validate
|
@@ -68,6 +69,11 @@ module Graphiti
|
|
68
69
|
|
69
70
|
def typecast_attributes(resource, attributes, payload_path)
|
70
71
|
attributes.each_pair do |key, value|
|
72
|
+
# Only validate id if create action, otherwise it's only used for lookup
|
73
|
+
next if @action != :create &&
|
74
|
+
key == :id &&
|
75
|
+
resource.class.config[:attributes][:id][:writable] == false
|
76
|
+
|
71
77
|
begin
|
72
78
|
attributes[key] = resource.typecast(key, value, :writable)
|
73
79
|
rescue Graphiti::Errors::UnknownAttribute
|
@@ -93,7 +93,7 @@ module Graphiti
|
|
93
93
|
original = Graphiti.context[:namespace]
|
94
94
|
begin
|
95
95
|
Graphiti.context[:namespace] = action
|
96
|
-
::Graphiti::RequestValidator.new(@resource, @payload.params).validate!
|
96
|
+
::Graphiti::RequestValidator.new(@resource, @payload.params, action).validate!
|
97
97
|
validator = persist {
|
98
98
|
@resource.persist_with_relationships \
|
99
99
|
@payload.meta(action: action),
|
@@ -118,6 +118,7 @@ module Graphiti
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def destroy
|
121
|
+
data
|
121
122
|
transaction_response = @resource.transaction do
|
122
123
|
metadata = {method: :destroy}
|
123
124
|
model = @resource.destroy(@query.filters[:id], metadata)
|
@@ -135,6 +136,7 @@ module Graphiti
|
|
135
136
|
end
|
136
137
|
|
137
138
|
def update_attributes
|
139
|
+
data
|
138
140
|
save(action: :update)
|
139
141
|
end
|
140
142
|
|
data/lib/graphiti/runner.rb
CHANGED
@@ -9,8 +9,7 @@ module Graphiti
|
|
9
9
|
@query = query
|
10
10
|
@action = action
|
11
11
|
|
12
|
-
validator = RequestValidator.new(jsonapi_resource, params)
|
13
|
-
|
12
|
+
validator = RequestValidator.new(jsonapi_resource, params, action)
|
14
13
|
validator.validate!
|
15
14
|
|
16
15
|
@deserialized_payload = validator.deserialized_payload
|
data/lib/graphiti/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializable
|