graphiti 1.2.37 → 1.2.42

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: 1ae9a52df4d54256b453573dc02f8eb2d8b1ad062eec7b38be89e3fbc7c6a9f3
4
- data.tar.gz: 99ce6f9e0067eae81661338a933561b2c573b8a78bd92551d6ef5b21a16e6cdf
3
+ metadata.gz: a282326a13780606dc7c66a393aecb4815e8230d166c21e522e4f64566fb7abe
4
+ data.tar.gz: efc784934b7091bba5839fe20c5052a5ee00198bc9a008f1330ab373ff26e965
5
5
  SHA512:
6
- metadata.gz: d77c8c268ef6c44b0557cf50fd3ecdfc71013fd25545cac6a935afd48f7e40caf47045af60649e03bf4f5ee01d8269d05f6be5991bc26a3c6303b7eb2d537afb
7
- data.tar.gz: e83bf82263f8b59b2e10a243238c85204631f0eca55ed3306d07129f30d099421d4b518c841bf460187329760d0f9920ff90f5136797cfa1ed13d5cf18d90b3d
6
+ metadata.gz: 396020335f1edb7b9a733cceaebecd3213e065567d83ca9c1380198967622a64927e3e9564715f4d3d76619a631005c87535fce7d094600a1d9d1b5cfd0cf42f
7
+ data.tar.gz: 64058843e61f8b50f5dfa44ed9835f73012ef6bb5c2c29b2c668d20b213571b59503c790c5ba62044f2300b8f0c3f49fd7159618e0ddc9280b12aee5236bf113
@@ -240,7 +240,8 @@ module Graphiti
240
240
  children.each do |child|
241
241
  if association_type == :many_to_many &&
242
242
  [:create, :update].include?(Graphiti.context[:namespace]) &&
243
- !parent.send(association_name).exists?(child.id)
243
+ !parent.send(association_name).exists?(child.id) &&
244
+ child.errors.blank?
244
245
  parent.send(association_name) << child
245
246
  else
246
247
  target = association.instance_variable_get(:@target)
@@ -34,6 +34,8 @@ module Graphiti
34
34
  def pagination_links?
35
35
  if Graphiti.config.pagination_links_on_demand
36
36
  [true, "true"].include?(@params[:pagination_links])
37
+ elsif action == :find
38
+ false
37
39
  else
38
40
  Graphiti.config.pagination_links
39
41
  end
@@ -25,7 +25,7 @@ module Graphiti
25
25
  end
26
26
  end
27
27
 
28
- typecast_attributes(resource, deserialized_payload.attributes, deserialized_payload.meta[:payload_path])
28
+ typecast_attributes(resource, deserialized_payload.attributes, @action, deserialized_payload.meta[:payload_path])
29
29
  process_relationships(resource, deserialized_payload.relationships, deserialized_payload.meta[:payload_path])
30
30
  else
31
31
  errors.add(:"data.type", :missing)
@@ -65,15 +65,20 @@ module Graphiti
65
65
  next
66
66
  end
67
67
 
68
- typecast_attributes(x[:resource], x[:attributes], x[:meta][:payload_path])
69
- process_relationships(x[:resource], x[:relationships], x[:meta][:payload_path])
68
+ resource = x[:resource]
69
+ attributes = x[:attributes]
70
+ relationships = x[:relationships]
71
+ payload_path = x[:meta][:payload_path]
72
+ action = x[:meta][:method]
73
+ typecast_attributes(resource, attributes, action, payload_path)
74
+ process_relationships(resource, relationships, payload_path)
70
75
  end
71
76
  end
72
77
 
73
- def typecast_attributes(resource, attributes, payload_path)
78
+ def typecast_attributes(resource, attributes, action, payload_path)
74
79
  attributes.each_pair do |key, value|
75
80
  # Only validate id if create action, otherwise it's only used for lookup
76
- next if @action != :create &&
81
+ next if action != :create &&
77
82
  key == :id &&
78
83
  resource.class.config[:attributes][:id][:writable] == false
79
84
 
@@ -137,11 +137,16 @@ module Graphiti
137
137
  end
138
138
 
139
139
  def link_extra_fields
140
+ return unless context&.respond_to?(:params)
141
+
140
142
  extra_fields_name = [association_name, resource.type].find { |param|
141
143
  context.params.dig(:extra_fields, param)
142
144
  }
143
145
 
144
- {resource.type => context.params.dig(:extra_fields, extra_fields_name)} if extra_fields_name
146
+ if extra_fields_name
147
+ extra_fields = context.params.dig(:extra_fields, extra_fields_name)
148
+ {resource.type => extra_fields}
149
+ end
145
150
  end
146
151
 
147
152
  # The parent resource is a remote,
@@ -16,13 +16,11 @@ module Graphiti
16
16
 
17
17
  if @name == :id
18
18
  @serializer.id(&proc)
19
- elsif @attr[:proc]
19
+ elsif @attr[:proc] ||
20
+ !previously_applied? ||
21
+ previously_applied_via_resource?
20
22
  @serializer.send(_method, @name, serializer_options, &proc)
21
- elsif @serializer.attribute_blocks[@name].nil?
22
- @serializer.send(_method, @name, serializer_options, &proc)
23
- elsif @serializer.send(applied_method).include?(@name)
24
- @serializer.field_condition_blocks[@name] = guard if guard?
25
- else
23
+ else # Previously applied via explicit serializer, so wrap it
26
24
  inner = @serializer.attribute_blocks.delete(@name)
27
25
  wrapped = wrap_proc(inner)
28
26
  @serializer.send(_method, @name, serializer_options, &wrapped)
@@ -34,6 +32,14 @@ module Graphiti
34
32
 
35
33
  private
36
34
 
35
+ def previously_applied?
36
+ @serializer.attribute_blocks[@name].present?
37
+ end
38
+
39
+ def previously_applied_via_resource?
40
+ @serializer.send(applied_method).include?(@name)
41
+ end
42
+
37
43
  def previously_guarded?
38
44
  @serializer.field_condition_blocks[@name]
39
45
  end
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.2.37"
2
+ VERSION = "1.2.42"
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.37
4
+ version: 1.2.42
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-20 00:00:00.000000000 Z
11
+ date: 2021-05-09 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.6
364
+ rubygems_version: 3.0.3
365
365
  signing_key:
366
366
  specification_version: 4
367
367
  summary: Easily build jsonapi.org-compatible APIs