graphiti 1.2.19 → 1.2.20

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: cd17ed21a3a7d08e6a1cf0ee76827f1d539091f08234adf596fe9287089305c6
4
- data.tar.gz: ee470506b0ccb4d5dc6e0a132021eb2f22e8b6de60e12733922a9a1ca51d0617
3
+ metadata.gz: db3bae18176af83f5ac1b88c50546cefcf57f38245e69a5fcbb45f3028ca2273
4
+ data.tar.gz: 6ee077531421990da7d4fe80bedfada136b299420d7b82566e9261b7f1a2800a
5
5
  SHA512:
6
- metadata.gz: '058c85a01c7eeb6bf9318500d0b77d143d1b259872e5f98b8470dcce8ca5e5a31d3e4213e032e9c512dec4b00522a4c2030e851e2f0e2f41b23e900876b4c575'
7
- data.tar.gz: 7680fe2ffca53e9d8c2ab9ac35ca5ad5c2eb1f4ae2417dc8e233f847ca4e36fad5ec383ed6971c0e325f7a4daa6cb6feffaf19971d1fbebd0437d0585ec24e32
6
+ metadata.gz: 0ceeabdfe64a03c4d709353a763a49224a14eb068633dcbd67c4ef2ee370dbdcd47781b0a4c15f19fe02956712aaca3dda42a17eb514bf44b821725261dc7ddf
7
+ data.tar.gz: d329a82610a68dec935625edbd502e85c39907a64261f170d342f632c82dc211c0fab440edbb16210483eb2154f44d403a2f13d5f3b9b7e41d4aafe68c66bf4a
@@ -1,7 +1,7 @@
1
1
  ## Unreleased
2
2
 
3
3
  Features:
4
-
4
+ - [242](https://github.com/graphiti-api/graphiti/pull/242) Bump `jsonapi-renderer` to `~0.2.2` now that (https://github.com/jsonapi-rb/jsonapi-renderer/pull/36) is fixed.
5
5
  - [158](https://github.com/graphiti-api/graphiti/pull/158) Filters options `allow_nil: true`
6
6
  Option can be set at the resource level `Resource.filters_accept_nil_by_default = true`.
7
7
  By default this is set to false. (@zeisler)
data/Gemfile CHANGED
@@ -3,6 +3,8 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in graphiti.gemspec
4
4
  gemspec
5
5
 
6
+ gem "standard", "0.4.7"
7
+
6
8
  group :test do
7
9
  gem "pry"
8
10
  gem "pry-byebug", platform: [:mri]
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  guard :rspec, cmd: "bundle exec rspec --color --format documentation" do
2
2
  require "guard/rspec/dsl"
3
3
  dsl = Guard::RSpec::Dsl.new(self)
4
- watch(%r{^spec/(.*)\/?(.*)_spec\.rb$})
4
+ watch(%r{^spec/(.*)/?(.*)_spec\.rb$})
5
5
 
6
6
  # Feel free to open issues for suggestions and improvements
7
7
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.required_ruby_version = "~> 2.3"
20
20
 
21
21
  spec.add_dependency "jsonapi-serializable", "~> 0.3.0"
22
- spec.add_dependency "jsonapi-renderer", "0.2.0"
22
+ spec.add_dependency "jsonapi-renderer", "~> 0.2", ">= 0.2.2"
23
23
  spec.add_dependency "dry-types", ">= 0.15.0", "< 2.0"
24
24
  spec.add_dependency "graphiti_errors", "~> 1.1.0"
25
25
  spec.add_dependency "concurrent-ruby", "~> 1.0"
@@ -31,5 +31,4 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  spec.add_development_dependency "activemodel", ">= 4.1"
33
33
  spec.add_development_dependency "graphiti_spec_helpers", "1.0.beta.4"
34
- spec.add_development_dependency "standard"
35
34
  end
@@ -159,7 +159,7 @@ module Graphiti
159
159
 
160
160
  # Ensure fractional seconds don't matter
161
161
  def filter_datetime_eq(scope, attribute, value, is_not: false)
162
- ranges = value.map { |v| (v..v + 1.second - 0.00000001) }
162
+ ranges = value.map { |v| (v..v + 1.second - 0.00000001) unless v.nil? }
163
163
  clause = {attribute => ranges}
164
164
  is_not ? scope.where.not(clause) : scope.where(clause)
165
165
  end
@@ -36,7 +36,8 @@ class Graphiti::Adapters::ActiveRecord::ManyToManySideload < Graphiti::Sideload:
36
36
 
37
37
  def filter_for(scope, value, type = nil)
38
38
  scope
39
- .includes(through_relationship_name)
39
+ .preload(through_relationship_name)
40
+ .joins(through_relationship_name)
40
41
  .where(belongs_to_many_clause(value, type))
41
42
  end
42
43
 
@@ -43,7 +43,7 @@ module Graphiti
43
43
  def extra_attribute(name, options = {}, &blk)
44
44
  allow_field = proc {
45
45
  if options[:if]
46
- next false unless instance_eval(&options[:if])
46
+ next false unless instance_exec(&options[:if])
47
47
  end
48
48
 
49
49
  @extra_fields &&
@@ -1,8 +1,8 @@
1
1
  module Graphiti
2
2
  class Query
3
- attr_reader :resource, :association_name, :params
3
+ attr_reader :resource, :association_name, :params, :action
4
4
 
5
- def initialize(resource, params, association_name = nil, nested_include = nil, parents = [])
5
+ def initialize(resource, params, association_name = nil, nested_include = nil, parents = [], action = nil)
6
6
  @resource = resource
7
7
  @association_name = association_name
8
8
  @params = params
@@ -11,6 +11,7 @@ module Graphiti
11
11
  @params = @params.deep_symbolize_keys
12
12
  @include_param = nested_include || @params[:include]
13
13
  @parents = parents
14
+ @action = parse_action(action)
14
15
  end
15
16
 
16
17
  def association?
@@ -95,7 +96,7 @@ module Graphiti
95
96
  sl_resource = resource_for_sideload(sideload)
96
97
  query_parents = parents + [self]
97
98
  sub_hash = sub_hash[:include] if sub_hash.key?(:include)
98
- hash[key] = Query.new(sl_resource, @params, key, sub_hash, query_parents)
99
+ hash[key] = Query.new(sl_resource, @params, key, sub_hash, query_parents, :all)
99
100
  else
100
101
  handle_missing_sideload(key)
101
102
  end
@@ -315,5 +316,17 @@ module Graphiti
315
316
  end
316
317
  end
317
318
  end
319
+
320
+ def parse_action(action)
321
+ action ||= @params.fetch(:action, Graphiti.context[:namespace]).try(:to_sym)
322
+ case action
323
+ when :index
324
+ :all
325
+ when :show
326
+ :find
327
+ else
328
+ action
329
+ end
330
+ end
318
331
  end
319
332
  end
@@ -135,6 +135,7 @@ module Graphiti
135
135
  filterable: false
136
136
  }
137
137
  options = defaults.merge(options)
138
+ attribute_option(options, :readable)
138
139
  config[:extra_attributes][name] = options
139
140
  apply_extra_attributes_to_serializer
140
141
  end
@@ -11,7 +11,7 @@ module Graphiti
11
11
 
12
12
  # @api private
13
13
  def _all(params, opts, base_scope)
14
- runner = Runner.new(self, params, opts.delete(:query))
14
+ runner = Runner.new(self, params, opts.delete(:query), :all)
15
15
  opts[:params] = params
16
16
  runner.proxy(base_scope, opts)
17
17
  end
@@ -27,7 +27,7 @@ module Graphiti
27
27
  params[:filter] ||= {}
28
28
  params[:filter][:id] = id if id
29
29
 
30
- runner = Runner.new(self, params)
30
+ runner = Runner.new(self, params, nil, :find)
31
31
  runner.proxy base_scope,
32
32
  single: true,
33
33
  raise_on_missing: true,
@@ -3,10 +3,11 @@ module Graphiti
3
3
  attr_reader :params
4
4
  attr_reader :deserialized_payload
5
5
 
6
- def initialize(resource_class, params, query = nil)
6
+ def initialize(resource_class, params, query = nil, action = nil)
7
7
  @resource_class = resource_class
8
8
  @params = params
9
9
  @query = query
10
+ @action = action
10
11
 
11
12
  validator = RequestValidator.new(jsonapi_resource, params)
12
13
 
@@ -30,7 +31,7 @@ module Graphiti
30
31
  end
31
32
 
32
33
  def query
33
- @query ||= Query.new(jsonapi_resource, params)
34
+ @query ||= Query.new(jsonapi_resource, params, nil, nil, [], @action)
34
35
  end
35
36
 
36
37
  def query_hash
@@ -132,6 +132,10 @@ module Graphiti
132
132
  end
133
133
  end
134
134
 
135
+ def link_filter(parents)
136
+ base_filter(parents)
137
+ end
138
+
135
139
  # The parent resource is a remote,
136
140
  # AND the sideload is a remote to the same endpoint
137
141
  def shared_remote?
@@ -1,8 +1,18 @@
1
1
  class Graphiti::Sideload::HasMany < Graphiti::Sideload
2
+ def initialize(name, opts)
3
+ @inverse_filter = opts[:inverse_filter]
4
+
5
+ super(name, opts)
6
+ end
7
+
2
8
  def type
3
9
  :has_many
4
10
  end
5
11
 
12
+ def inverse_filter
13
+ @inverse_filter || foreign_key
14
+ end
15
+
6
16
  def load_params(parents, query)
7
17
  query.hash.tap do |hash|
8
18
  hash[:filter] ||= {}
@@ -11,11 +21,19 @@ class Graphiti::Sideload::HasMany < Graphiti::Sideload
11
21
  end
12
22
 
13
23
  def base_filter(parents)
14
- {foreign_key => ids_for_parents(parents).join(",")}
24
+ {foreign_key => parent_filter(parents)}
25
+ end
26
+
27
+ def link_filter(parents)
28
+ {inverse_filter => parent_filter(parents)}
15
29
  end
16
30
 
17
31
  private
18
32
 
33
+ def parent_filter(parents)
34
+ ids_for_parents(parents).join(",")
35
+ end
36
+
19
37
  def child_map(children)
20
38
  children.group_by(&foreign_key)
21
39
  end
@@ -11,8 +11,12 @@ class Graphiti::Sideload::ManyToMany < Graphiti::Sideload::HasMany
11
11
  foreign_key.values.first
12
12
  end
13
13
 
14
+ def inverse_filter
15
+ @inverse_filter || true_foreign_key
16
+ end
17
+
14
18
  def base_filter(parents)
15
- {true_foreign_key => ids_for_parents(parents).join(",")}
19
+ {true_foreign_key => parent_filter(parents)}
16
20
  end
17
21
 
18
22
  def infer_foreign_key
@@ -32,7 +36,7 @@ class Graphiti::Sideload::ManyToMany < Graphiti::Sideload::HasMany
32
36
  self_ref = self
33
37
  fk_type = parent_resource_class.attributes[:id][:type]
34
38
  fk_type = :hash if polymorphic?
35
- resource_class.filter true_foreign_key, fk_type do
39
+ resource_class.filter inverse_filter, fk_type do
36
40
  eq do |scope, value|
37
41
  self_ref.belongs_to_many_filter(scope, value)
38
42
  end
@@ -60,7 +60,7 @@ module Graphiti
60
60
  def params
61
61
  @params ||= {}.tap do |params|
62
62
  if @sideload.type != :belongs_to || @sideload.remote?
63
- params[:filter] = @sideload.base_filter([@model])
63
+ params[:filter] = @sideload.link_filter([@model])
64
64
  end
65
65
 
66
66
  @sideload.params_proc&.call(params, [@model], context)
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.2.19"
2
+ VERSION = "1.2.20"
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.19
4
+ version: 1.2.20
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-05-20 00:00:00.000000000 Z
11
+ date: 2020-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable
@@ -28,16 +28,22 @@ dependencies:
28
28
  name: jsonapi-renderer
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ - - ">="
32
35
  - !ruby/object:Gem::Version
33
- version: 0.2.0
36
+ version: 0.2.2
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - '='
41
+ - - "~>"
39
42
  - !ruby/object:Gem::Version
40
- version: 0.2.0
43
+ version: '0.2'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.2.2
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: dry-types
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -184,20 +190,6 @@ dependencies:
184
190
  - - '='
185
191
  - !ruby/object:Gem::Version
186
192
  version: 1.0.beta.4
187
- - !ruby/object:Gem::Dependency
188
- name: standard
189
- requirement: !ruby/object:Gem::Requirement
190
- requirements:
191
- - - ">="
192
- - !ruby/object:Gem::Version
193
- version: '0'
194
- type: :development
195
- prerelease: false
196
- version_requirements: !ruby/object:Gem::Requirement
197
- requirements:
198
- - - ">="
199
- - !ruby/object:Gem::Version
200
- version: '0'
201
193
  description:
202
194
  email:
203
195
  - richmolj@gmail.com