graphiti-activegraph 0.1.23 → 0.1.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: d88ca37172c5b507a37ae3744f0a2ac86485b47f5494f0e080f6dbe7e7137738
4
- data.tar.gz: b78b22b43bc9913ded8262a5d5d16fa2a6d6d5dbc0d8f4b0cfa094231289f858
3
+ metadata.gz: 91f9eb76f0b56c276cf1ec4fbef4d535e768c85dbee0d503c3bf9e47c492b509
4
+ data.tar.gz: 9ead092210d92a237fed63c396cf302730fffe601d1fcb0a00a1265563cc0c66
5
5
  SHA512:
6
- metadata.gz: 663ff44a72d8f833f5156e3dd0d3a960c3c77220a0b9191b20afc15104013d267f92c9ff1ed22927f405199c3bc074fa92bbed4d5f57063150a778f7efe5dcc9
7
- data.tar.gz: 9f19e81f5b2c7fd70585a3ef493a83c06080df69593ae23bd56fd723950ef87a2ecd4c05a6c475c87e1efc627a256aad4597a0c8b77fc731ad7a04b380030892
6
+ metadata.gz: 48334374bd34917e110d55156847d8cc3ba389e45dc76bb7d3db1df2ca8cc59cda5a46ff23c79aff298e0700201d743d3ca04d53b0bb4ae843a3db037c13bff9
7
+ data.tar.gz: cb3ee1de2754dcd3ddfcccc84970aaffc21fa8c2c05e6518299c6bd55c7a4f52830462a9a092152eeb93ece42e3476532094d41bf41d57683eb43d34cf9b1f64
data/.gitignore CHANGED
@@ -45,7 +45,7 @@ build-iPhoneSimulator/
45
45
 
46
46
  # for a library or gem, you might want to ignore these files since the code is
47
47
  # intended to run in multiple environments; otherwise, check them in:
48
- # Gemfile.lock
48
+ /Gemfile.lock
49
49
  # .ruby-version
50
50
  # .ruby-gemset
51
51
 
data/CHANGELOG.md CHANGED
@@ -44,12 +44,24 @@ Fixes:
44
44
 
45
45
  - when rendering preloaded resources, we were not applying scoping. Now we are skipping around_scoping callback too.
46
46
 
47
- ## 0.1.22 (29-04-2024)
47
+ ## 0.1.23 (29-04-2024)
48
48
 
49
49
  Features:
50
50
 
51
51
  - Added support for UUID
52
52
 
53
+ ## 0.1.24 (18-06-2024)
54
+
55
+ Features:
56
+
57
+ - Added preliminary support for Sideload backed by function instead of model association
58
+
59
+ ## 0.1.25 (04-12-2024)
60
+
61
+ Features:
62
+
63
+ - Added support to preload extra_fields for the main resource, replacing N+1 queries with a single query. This does not apply to sideloaded resources.
64
+
53
65
  <!-- ### [version (DD-MM-YYYY)] -->
54
66
  <!-- Breaking changes:-->
55
67
  <!-- Features:-->
@@ -25,6 +25,9 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "faraday", "~> 0.15"
26
26
  spec.add_development_dependency "kaminari", "~> 0.17"
27
27
  spec.add_development_dependency "bundler"
28
+ # dependency conflict introduced during runtime
29
+ # jar-dependencies is a default gem in JRuby and also a dependency in neo4j-ruby-driver
30
+ spec.add_development_dependency "jar-dependencies", "~> 0.4.1"
28
31
  spec.add_development_dependency "rake", "~> 10.0"
29
32
  spec.add_development_dependency "graphiti_spec_helpers", "1.0.beta.4"
30
33
  spec.add_development_dependency "standard"
@@ -0,0 +1,15 @@
1
+ class Graphiti::ActiveGraph::Adapters::ActiveGraph::FunctionSideload < Graphiti::ActiveGraph::Adapters::ActiveGraph::HasOneSideload
2
+ class_attribute :function_proc, :param_proc
3
+
4
+ def association?
5
+ false
6
+ end
7
+
8
+ def self.function_proc(&blk)
9
+ self.function_proc = blk
10
+ end
11
+
12
+ def self.param_proc(&blk)
13
+ self.param_proc = blk
14
+ end
15
+ end
@@ -45,10 +45,5 @@ module Graphiti::ActiveGraph
45
45
  def sort_criteria(sort)
46
46
  sort.split(',').map(&method(:sort_hash)).map(&method(:parse_sort_criteria_hash))
47
47
  end
48
-
49
- def update_include_hash(authorized_include_param)
50
- @include_hash = authorized_include_param
51
- @sideloads = nil
52
- end
53
48
  end
54
49
  end
@@ -23,6 +23,10 @@ module Graphiti
23
23
 
24
24
  def guard_nil_id!(params)
25
25
  end
26
+
27
+ def extra_attribute?(name)
28
+ extra_attributes.has_key?(name)
29
+ end
26
30
  end
27
31
 
28
32
  module ResourceInstanceMethods
@@ -30,6 +34,10 @@ module Graphiti
30
34
  self.class.relation_resource?
31
35
  end
32
36
 
37
+ def extra_attribute?(name)
38
+ self.class.extra_attribute?(name)
39
+ end
40
+
33
41
  def sideload_name_arr(query)
34
42
  query.sideloads.keys.map(&:to_sym)
35
43
  end
@@ -1,5 +1,7 @@
1
1
  module Graphiti::ActiveGraph
2
2
  module SideloadResolve
3
+ PRELOAD_METHOD_PREFIX = 'preload_'.freeze
4
+
3
5
  def initialize(object, resource, query, opts = {})
4
6
  @object = object
5
7
  @resource = resource
@@ -15,5 +17,40 @@ module Graphiti::ActiveGraph
15
17
 
16
18
  def resolve_sideloads(parents)
17
19
  end
20
+
21
+ def resolve
22
+ super.tap { |results| preload_extra_fields(results) }
23
+ end
24
+
25
+ private
26
+
27
+ def preload_extra_fields(results)
28
+ requested_extra_fields.each do |extra_field_name|
29
+ next unless preload_extra_field?(extra_field_name)
30
+
31
+ result_map = fetch_preloaded_data(extra_field_name, results)
32
+ assign_preloaded_data(results, extra_field_name, result_map)
33
+ end
34
+ end
35
+
36
+ def requested_extra_fields
37
+ @query.extra_fields[@resource.type] || []
38
+ end
39
+
40
+ def fetch_preloaded_data(extra_field_name, results)
41
+ @resource.model.public_send(default_preload_method(extra_field_name), results.pluck(:id))
42
+ end
43
+
44
+ def assign_preloaded_data(results, extra_field_name, result_map)
45
+ results.each { |r| r.public_send("#{extra_field_name}=", result_map[r.id]) }
46
+ end
47
+
48
+ def preload_extra_field?(extra_field_name)
49
+ @resource.extra_attribute?(extra_field_name) && @resource.model.respond_to?(default_preload_method(extra_field_name))
50
+ end
51
+
52
+ def default_preload_method(extra_field_name)
53
+ "#{PRELOAD_METHOD_PREFIX}#{extra_field_name}"
54
+ end
18
55
  end
19
56
  end
@@ -1,5 +1,5 @@
1
1
  module Graphiti
2
2
  module ActiveGraph
3
- VERSION = '0.1.23'
3
+ VERSION = '0.1.25'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti-activegraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hardik Joshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-29 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.4.1
117
+ name: jar-dependencies
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.4.1
111
125
  - !ruby/object:Gem::Dependency
112
126
  requirement: !ruby/object:Gem::Requirement
113
127
  requirements:
@@ -194,6 +208,7 @@ files:
194
208
  - graphiti-activegraph.gemspec
195
209
  - lib/graphiti-activegraph.rb
196
210
  - lib/graphiti/active_graph/adapters/active_graph.rb
211
+ - lib/graphiti/active_graph/adapters/active_graph/function_sideload.rb
197
212
  - lib/graphiti/active_graph/adapters/active_graph/has_many_sideload.rb
198
213
  - lib/graphiti/active_graph/adapters/active_graph/has_one_sideload.rb
199
214
  - lib/graphiti/active_graph/adapters/active_graph/polymorphic_belongs_to.rb