graphiti 1.2.34 → 1.2.35

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c877600c2b854433fd506185d43e64fce4e9f6c3a7cd37846fe60f724acd8f4
4
- data.tar.gz: d1e30c54a384eda5a2b2f5224da346808c47a54aadf57610b1ccd7339d780234
3
+ metadata.gz: 5aaea1da30c8eb6b86abc1be0df8fba47d2df8f55be42f6141f78976a2c02dea
4
+ data.tar.gz: c4611d1226bc10b04a755e29943bc131831cb9df23cb55480ab3daa3cfa8d4b5
5
5
  SHA512:
6
- metadata.gz: 68b7f4d1d96c67d6d28976ed9ba8071e5d8376835cfbc61a2744e9792467e93dee4b4338fbeb4d7d3492f8a03aa935657726c0b66d0af69f4d061b5cdc29f1b7
7
- data.tar.gz: 62a8b811497bfc1ffc06e4bb85f86ac573be0f7eb7b0a41cf915f6c0ee9fdf85460612c17708956c89472a6b7dad0d43c0087212db2779e0320211d9f99a93c9
6
+ metadata.gz: 20c0ca9615484a566e528c5851702dfff7436c37e3ccf7774ef37611699397870bb74be19f633b1dfc9eca9c315642a29777412c66823550290bca8406e6a254
7
+ data.tar.gz: 1edb1ae4364f3b348fa74dffc6c8a794b0e54d39289144614e0c9e605e0dc3df6f850ea72b7117f99a72725ffc9cf536cda93a9694ee3a39a7cc21748405973b
@@ -26,17 +26,17 @@ module Graphiti
26
26
  [:data, :type],
27
27
  [:data, :id]
28
28
  ].each do |required_attr|
29
- attribute_mismatch(required_attr) unless @raw_params.dig(*required_attr)
29
+ attribute_mismatch(required_attr) unless @params.dig(*required_attr)
30
30
  end
31
31
  errors.blank?
32
32
  end
33
33
 
34
34
  def payload_matches_endpoint?
35
- unless @raw_params.dig(:data, :id) == @raw_params.dig(:filter, :id)
35
+ unless @params.dig(:data, :id) == @params.dig(:filter, :id)
36
36
  attribute_mismatch([:data, :id])
37
37
  end
38
38
 
39
- meta_type = @raw_params.dig(:data, :type)
39
+ meta_type = @params.dig(:data, :type)
40
40
 
41
41
  # NOTE: calling #to_s and comparing 2 strings is slower than
42
42
  # calling #to_sym and comparing 2 symbols. But pre ruby-2.2
@@ -5,21 +5,31 @@ module Graphiti
5
5
 
6
6
  def initialize(root_resource, raw_params, action)
7
7
  @root_resource = root_resource
8
- @raw_params = raw_params
8
+ @params = normalized_params(raw_params)
9
9
  @errors = Graphiti::Util::SimpleErrors.new(raw_params)
10
10
  @action = action
11
11
  end
12
12
 
13
13
  def validate
14
+ # Right now, all requests - even reads - go through the validator
15
+ # In the future these should have their own validation logic, but
16
+ # for now we can just bypass
17
+ return true unless @params.has_key?(:data)
18
+
14
19
  resource = @root_resource
15
- if (meta_type = deserialized_payload.meta[:type].try(:to_sym))
16
- if @root_resource.type != meta_type && @root_resource.polymorphic?
17
- resource = @root_resource.class.resource_for_type(meta_type).new
20
+
21
+ if @params[:data].has_key?(:type)
22
+ if (meta_type = deserialized_payload.meta[:type].try(:to_sym))
23
+ if @root_resource.type != meta_type && @root_resource.polymorphic?
24
+ resource = @root_resource.class.resource_for_type(meta_type).new
25
+ end
18
26
  end
19
- end
20
27
 
21
- typecast_attributes(resource, deserialized_payload.attributes, deserialized_payload.meta[:payload_path])
22
- process_relationships(resource, deserialized_payload.relationships, deserialized_payload.meta[:payload_path])
28
+ typecast_attributes(resource, deserialized_payload.attributes, deserialized_payload.meta[:payload_path])
29
+ process_relationships(resource, deserialized_payload.relationships, deserialized_payload.meta[:payload_path])
30
+ else
31
+ errors.add(:"data.type", :missing)
32
+ end
23
33
 
24
34
  errors.blank?
25
35
  end
@@ -33,14 +43,7 @@ module Graphiti
33
43
  end
34
44
 
35
45
  def deserialized_payload
36
- @deserialized_payload ||= begin
37
- payload = normalized_params
38
- if payload[:data] && payload[:data][:type]
39
- Graphiti::Deserializer.new(payload)
40
- else
41
- Graphiti::Deserializer.new({})
42
- end
43
- end
46
+ @deserialized_payload ||= Graphiti::Deserializer.new(@params)
44
47
  end
45
48
 
46
49
  private
@@ -86,8 +89,8 @@ module Graphiti
86
89
  end
87
90
  end
88
91
 
89
- def normalized_params
90
- normalized = @raw_params
92
+ def normalized_params(raw_params)
93
+ normalized = raw_params
91
94
  if normalized.respond_to?(:to_unsafe_h)
92
95
  normalized = normalized.to_unsafe_h.deep_symbolize_keys
93
96
  end
@@ -3,10 +3,12 @@ module Graphiti
3
3
  include Scoping::Filterable
4
4
 
5
5
  def apply
6
- Graphiti::Scoping::FilterGroupValidator.new(
7
- resource,
8
- query_hash
9
- ).raise_unless_filter_group_requirements_met!
6
+ unless @opts[:bypass_required_filters]
7
+ Graphiti::Scoping::FilterGroupValidator.new(
8
+ resource,
9
+ query_hash
10
+ ).raise_unless_filter_group_requirements_met!
11
+ end
10
12
 
11
13
  if missing_required_filters.any? && !@opts[:bypass_required_filters]
12
14
  raise Errors::RequiredFilter.new(resource, missing_required_filters)
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.2.34"
2
+ VERSION = "1.2.35"
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.34
4
+ version: 1.2.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-16 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable
@@ -361,7 +361,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
361
361
  - !ruby/object:Gem::Version
362
362
  version: '0'
363
363
  requirements: []
364
- rubygems_version: 3.0.1
364
+ rubygems_version: 3.0.6
365
365
  signing_key:
366
366
  specification_version: 4
367
367
  summary: Easily build jsonapi.org-compatible APIs