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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36b58f545ff99d459f7739072dd54045a8eee7f06990f7cee8450c1311788feb
4
- data.tar.gz: bab55c98392e96c793b51bac6423c63b171782f36fddd3ef57531e4d3f280f9b
3
+ metadata.gz: d5f2ffef76f6dd895acddc9a4d2deb374a3d217c94d0c85fd1feb40ecac9f369
4
+ data.tar.gz: c6ce48631bf54161b0678ac5d16a8e25b49c8259ec1405138559814745569129
5
5
  SHA512:
6
- metadata.gz: dc9a8a3dce388ba6cec8100cbbd16c0c04e7aa0559acd2d3b028d00ce869537fce70c395e524c33351b4066142a48cecd3ee76bbf6c8d8b25e1fb38e997b0556
7
- data.tar.gz: fbf3374a770546d24e62ebbc96091264f823ddeaaf99329eb0f51dfcfb918df999dcf6025aeb87868754671c079058e9a3e664db15c77cf6e00f1958a1b80ddd
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 raw_params["action"]
16
- when "update" then
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
@@ -5,6 +5,7 @@ module Graphiti
5
5
 
6
6
  class_methods do
7
7
  def filter(name, *args, &blk)
8
+ name = name.to_sym
8
9
  opts = args.extract_options!
9
10
  type_override = args[0]
10
11
 
@@ -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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.2.21"
2
+ VERSION = "1.2.25"
3
3
  end
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.21
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-07-26 00:00:00.000000000 Z
11
+ date: 2020-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable