graphiti 1.0.rc.8 → 1.0.rc.9

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
  SHA1:
3
- metadata.gz: b5bb7bbf101a447f9036ac8dd26e8ac958180411
4
- data.tar.gz: 8634cc52129745771738c95def507df6cf71d73e
3
+ metadata.gz: b671896a39d2dbafcbba2aeff6f28b84975716c5
4
+ data.tar.gz: '08d51b340c5311838a386a6b623140b52b4f9109'
5
5
  SHA512:
6
- metadata.gz: a9e7dfafa6429aa5ebe4e5dbd273d2cd6294e599c2ac8ee7539917af343f05c9a4f395d0b50dc2ccf8f734986b3b7c38f5f74bc74788b6d3530765965e350a65
7
- data.tar.gz: 3cdf7674cd137181b41edbe187ebfd8debb68e50ef0c1f6f15f9de725080dea8b33b4112480f991ae76266f112866a7584349b56c9db693c5919f0ef93ceadba
6
+ metadata.gz: 656b61085599d072b1af3d04e0356170e796c0bb02b1d7dabea43fffcc61ad14c4df6c9ef2c7fdb309e3c1fabcf5cfdecb694d99e66243a18fc11a1e982c6611
7
+ data.tar.gz: fa1068a26baeae8bdadcd3fe3406e8b15cfc7baa86e50edba8cd073916b9266df6fbd7d599bc147c0f01e29c59e80290775820c12bc7232da300fbff76279f87
@@ -210,24 +210,6 @@ module Graphiti
210
210
  not [false, 'false'].include?(@params[:paginate])
211
211
  end
212
212
 
213
- # If this is a remote call, we don't care about local parents
214
- def chain
215
- if @resource.remote
216
- top_remote_parent = parents.find { |p| p.resource.remote? }
217
- [].tap do |chain|
218
- parents.select { |p| p.resource.remote? }.each do |p|
219
- chain << p.association_name unless p == top_remote_parent
220
- end
221
- immediate_parent = parents.reverse[0]
222
- # This is not currently checking that it is a remote of the same API
223
- chain << association_name if immediate_parent && immediate_parent.resource.remote
224
- chain.compact
225
- end.compact
226
- else
227
- parents.map(&:association_name).compact + [association_name].compact
228
- end
229
- end
230
-
231
213
  private
232
214
 
233
215
  # Try to find on this resource
@@ -114,6 +114,7 @@ class Graphiti::Sideload::PolymorphicBelongsTo < Graphiti::Sideload::BelongsTo
114
114
  # but not others. Remove anything we don't support.
115
115
  def remove_invalid_sideloads(resource, query)
116
116
  query = query.dup
117
+ query.instance_variable_set(:@hash, nil)
117
118
  query.sideloads.each_pair do |key, value|
118
119
  unless resource.class.sideload(key)
119
120
  query.sideloads.delete(key)
@@ -12,16 +12,16 @@ class Graphiti::Util::Persistence
12
12
  @relationships = relationships
13
13
  @caller_model = caller_model
14
14
 
15
- @attributes.each_pair do |key, value|
16
- @attributes[key] = @resource.typecast(key, value, :writable)
17
- end
18
-
19
15
  # Find the correct child resource for a given jsonapi type
20
16
  if meta_type = @meta[:type].try(:to_sym)
21
17
  if @resource.type != meta_type && @resource.polymorphic?
22
18
  @resource = @resource.class.resource_for_type(meta_type).new
23
19
  end
24
20
  end
21
+
22
+ @attributes.each_pair do |key, value|
23
+ @attributes[key] = @resource.typecast(key, value, :writable)
24
+ end
25
25
  end
26
26
 
27
27
  # Perform the actual save logic.
@@ -80,6 +80,9 @@ class Graphiti::Util::Persistence
80
80
  return if x[:sideload].type == :many_to_many
81
81
 
82
82
  if [:destroy, :disassociate].include?(x[:meta][:method])
83
+ if x[:sideload].polymorphic_has_many?
84
+ attrs[:"#{x[:sideload].polymorphic_as}_type"] = nil
85
+ end
83
86
  attrs[x[:foreign_key]] = nil
84
87
  update_foreign_type(attrs, x, null: true) if x[:is_polymorphic]
85
88
  else
@@ -21,7 +21,7 @@ module Graphiti
21
21
  if include_hash = @query.include_hash.presence
22
22
  @params[:include] = trim_sideloads(include_hash)
23
23
  end
24
- collect_params(@query)
24
+ collect_params(@query, @resource)
25
25
  @params[:sort] = @sorts.join(',') if @sorts.present?
26
26
  @params[:filter] = @filters if @filters.present?
27
27
  @params[:page] = @pagination if @pagination.present?
@@ -33,13 +33,32 @@ module Graphiti
33
33
 
34
34
  private
35
35
 
36
- def collect_params(query)
36
+ # If this is a remote call, we don't care about local parents
37
+ # When polymorphic, query is top-level (ie, query.resource is
38
+ # the parent, not a child type implementation).
39
+ # This is why we pass BOTH the resource and the query
40
+ def query_chain(resource, query)
41
+ top_remote_parent = query.parents.find { |p| p.resource.remote? }
42
+ [].tap do |chain|
43
+ query.parents.select { |p| p.resource.remote? }.each do |p|
44
+ chain << p.association_name unless p == top_remote_parent
45
+ end
46
+ immediate_parent = query.parents.reverse[0]
47
+ # This is not currently checking that it is a remote of the same API
48
+ chain << query.association_name if immediate_parent && immediate_parent.resource.remote
49
+ chain.compact
50
+ end.compact
51
+ end
52
+
53
+ def collect_params(query, resource = nil)
37
54
  query_hash = query.hash
38
- process_sorts(query_hash[:sort], query)
55
+ resource ||= query.resource
56
+ chain = query_chain(resource, query)
57
+ process_sorts(query_hash[:sort], chain)
39
58
  process_fields(query.fields.merge(query.hash[:fields] || {}))
40
59
  process_extra_fields(query.extra_fields.merge(query.hash[:extra_fields] || {}))
41
- process_filters(query_hash[:filter], query)
42
- process_pagination(query_hash[:page], query)
60
+ process_filters(query_hash[:filter], chain)
61
+ process_pagination(query_hash[:page], chain)
43
62
  process_stats(query_hash[:stats])
44
63
 
45
64
  query.sideloads.each_pair do |assn_name, nested_query|
@@ -54,22 +73,22 @@ module Graphiti
54
73
  @stats = { stats.keys.first => stats.values.join(',') }
55
74
  end
56
75
 
57
- def process_pagination(page, query)
76
+ def process_pagination(page, chain)
58
77
  return unless page.present?
59
78
  if size = page[:size]
60
- key = (query.chain + [:size]).join('.')
79
+ key = (chain + [:size]).join('.')
61
80
  @pagination[key.to_sym] = size
62
81
  end
63
82
  if number = page[:number]
64
- key = (query.chain + [:number]).join('.')
83
+ key = (chain + [:number]).join('.')
65
84
  @pagination[key.to_sym] = number
66
85
  end
67
86
  end
68
87
 
69
- def process_filters(filters, query)
88
+ def process_filters(filters, chain)
70
89
  return unless filters.present?
71
90
  filters.each_pair do |att, config|
72
- att = (query.chain + [att]).join('.')
91
+ att = (chain + [att]).join('.')
73
92
  @filters[att.to_sym] = config
74
93
  end
75
94
  end
@@ -90,14 +109,14 @@ module Graphiti
90
109
  end
91
110
  end
92
111
 
93
- def process_sorts(sorts, query)
112
+ def process_sorts(sorts, chain)
94
113
  return unless sorts
95
114
 
96
115
  if sorts.is_a?(String) # manually assigned
97
116
  @sorts << sorts
98
117
  else
99
118
  sorts.each do |s|
100
- sort = (query.chain + [s.keys.first]).join('.')
119
+ sort = (chain + [s.keys.first]).join('.')
101
120
  sort = "-#{sort}" if s.values.first == :desc
102
121
  @sorts << sort
103
122
  end
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.0.rc.8"
2
+ VERSION = "1.0.rc.9"
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.0.rc.8
4
+ version: 1.0.rc.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-27 00:00:00.000000000 Z
11
+ date: 2019-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable