graphiti 1.7.7 → 1.7.8

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: ddc4dbb09c7011dedf5683e72705a6ae4b643aa429ad9d2d67476af442be827b
4
- data.tar.gz: d9957eddf4b8eafdd4f28122c5e4c37c52544718d527bc7a1800fed64bb8c3f2
3
+ metadata.gz: e36dfd471013c8ead523d885a475968aeb18947a268e7b7a68e03e10dcc9fd0d
4
+ data.tar.gz: a07c6145a4528154dc2592850c434225bfd607038bd80b55ee39efbbac803cb2
5
5
  SHA512:
6
- metadata.gz: 2afe757fa90a81c4879848cc1acd38966eb5e58d16af25606b6780005bb02bdb05ce0fdc82c24121891cc87ac3e490266f9c43b018d9981b0cda0facfe52ed76
7
- data.tar.gz: 75cdb65510070fd8af890956dbf0b18e4ba3ebd69f994f0d9c2c4b49f753e4537d5cc41bd9282dc0fefc8c1c9718abacf448ecad379faf52defaafff1c1ea52f
6
+ metadata.gz: f6cb999efba286de44b69bfb7a3a56333dbf78c2f51b3dc9359f0fff3da867a8a7bdc98cfa55cbef5f44e3146350d09a729f5d2edc43fb50dd02e264d30f1034
7
+ data.tar.gz: faebd5bf5f20ba3a6df4494c1f45aec44c630afd8841b78daad0e5e575bcd0932560e776c38fe38be77a4d6efd7dd1d59b184ae37ec449778f952b32cbd69562
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  graphiti changelog
2
2
 
3
+ ## [1.7.8](https://github.com/graphiti-api/graphiti/compare/v1.7.7...v1.7.8) (2025-03-16)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * compare URI-decoded path params ([#482](https://github.com/graphiti-api/graphiti/issues/482)) ([20b80dd](https://github.com/graphiti-api/graphiti/commit/20b80dd35bfa4e2f677af3fb9472def6da668149))
9
+ * correct issue with many_to_many when one of the models has a prefix to the intersection model association ([#449](https://github.com/graphiti-api/graphiti/issues/449)) ([dc28a4f](https://github.com/graphiti-api/graphiti/commit/dc28a4f72fe4c577e23ced102a0b5e7063ba8026))
10
+ * lazy constantize relation resources ([#492](https://github.com/graphiti-api/graphiti/issues/492)) ([3cc2983](https://github.com/graphiti-api/graphiti/commit/3cc298399b4dc8970a2beed49b333396c76bd218))
11
+
3
12
  ## [1.7.7](https://github.com/graphiti-api/graphiti/compare/v1.7.6...v1.7.7) (2025-03-15)
4
13
 
5
14
 
@@ -1,7 +1,6 @@
1
1
  class Graphiti::Adapters::ActiveRecord::ManyToManySideload < Graphiti::Sideload::ManyToMany
2
2
  def through_table_name
3
- @through_table_name ||= parent_resource_class.model
4
- .reflections[through.to_s].klass.table_name
3
+ @through_table_name ||= resource_class.model.reflections[through.to_s].klass.table_name
5
4
  end
6
5
 
7
6
  def through_relationship_name
@@ -168,6 +168,14 @@ module Graphiti
168
168
  scope
169
169
  end
170
170
 
171
+ def filter_uuid_eq(scope, attribute, value)
172
+ scope
173
+ end
174
+
175
+ def filter_uuid_not_eq(scope, attribute, value)
176
+ scope
177
+ end
178
+
171
179
  def base_scope(model)
172
180
  {}
173
181
  end
@@ -18,6 +18,7 @@ module Graphiti
18
18
  attr_accessor :before_sideload
19
19
 
20
20
  attr_reader :debug, :debug_models
21
+ attr_reader :uri_decoder
21
22
 
22
23
  attr_writer :schema_path
23
24
  attr_writer :cache_rendering
@@ -37,6 +38,8 @@ module Graphiti
37
38
  self.debug = ENV.fetch("GRAPHITI_DEBUG", true)
38
39
  self.debug_models = ENV.fetch("GRAPHITI_DEBUG_MODELS", false)
39
40
 
41
+ @uri_decoder = infer_uri_decoder
42
+
40
43
  # FIXME: Don't duplicate graphiti-rails efforts
41
44
  if defined?(::Rails.root) && (root = ::Rails.root)
42
45
  config_file = root.join(".graphiticfg.yml")
@@ -85,6 +88,33 @@ module Graphiti
85
88
  ensure
86
89
  send(:"#{key}=", original)
87
90
  end
91
+
92
+ def uri_decoder=(decoder)
93
+ unless decoder.respond_to?(:call)
94
+ raise "uri_decoder must respond to `call`."
95
+ end
96
+
97
+ @uri_decoder = decoder
98
+ end
99
+
100
+ private
101
+
102
+ def infer_uri_decoder
103
+ if defined?(::ActionDispatch::Journey::Router::Utils)
104
+ # available in all supported versions of Rails.
105
+ # This method should be preferred for comparing URI path segments
106
+ # to params, as it is the exact decoder used in the Rails router.
107
+ @uri_decoder = ::ActionDispatch::Journey::Router::Utils.method(:unescape_uri)
108
+ elsif URI.respond_to?(:decode_uri_component)
109
+ # available in Ruby >= 3.2
110
+ @uri_decoder = URI.method(:decode_uri_component)
111
+ end
112
+ rescue => e
113
+ Kernel.warn("Error inferring Graphiti uri_decoder: #{e}")
114
+ ensure
115
+ # fallback
116
+ @uri_decoder ||= :itself.to_proc
117
+ end
88
118
  end
89
119
 
90
120
  msg = "Use graphiti-rails's `config.graphiti.respond_to_formats`"
@@ -81,12 +81,12 @@ module Graphiti
81
81
  endpoints.any? do |e|
82
82
  has_id = params[:id] || params[:data].try(:[], :id)
83
83
  path = request_path
84
- if [:update, :show, :destroy].include?(context_namespace) && has_id
84
+ if [:update, :show, :destroy].include?(action) && has_id
85
85
  path = request_path.split("/")
86
- path.pop if path.last == has_id.to_s
86
+ path.pop if Graphiti::Util::UriDecoder.decode_uri(path.last) == has_id.to_s
87
87
  path = path.join("/")
88
88
  end
89
- e[:full_path].to_s == path && e[:actions].include?(context_namespace)
89
+ e[:full_path].to_s == path && e[:actions].include?(action)
90
90
  end
91
91
  end
92
92
 
@@ -21,7 +21,7 @@ module Graphiti
21
21
  @name = name
22
22
  validate_options!(opts)
23
23
  @parent_resource_class = opts[:parent_resource]
24
- @resource_class = opts[:resource]
24
+ @resource_class_name = opts[:resource]
25
25
  @primary_key = opts[:primary_key]
26
26
  @foreign_key = opts[:foreign_key]
27
27
  @type = opts[:type]
@@ -177,7 +177,8 @@ module Graphiti
177
177
  end
178
178
 
179
179
  def resource_class
180
- @resource_class ||= infer_resource_class
180
+ @resource_class ||= (@resource_class_name.is_a?(String) ? @resource_class_name.constantize : @resource_class_name) ||
181
+ infer_resource_class
181
182
  end
182
183
 
183
184
  def scope(parents)
@@ -0,0 +1,9 @@
1
+ module Graphiti
2
+ module Util
3
+ module UriDecoder
4
+ def self.decode_uri(uri)
5
+ Graphiti.config.uri_decoder.call(uri)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.7.7"
2
+ VERSION = "1.7.8"
3
3
  end
data/lib/graphiti.rb CHANGED
@@ -190,6 +190,7 @@ require "graphiti/serializer"
190
190
  require "graphiti/query"
191
191
  require "graphiti/debugger"
192
192
  require "graphiti/util/cache_debug"
193
+ require "graphiti/util/uri_decoder"
193
194
 
194
195
  if defined?(ActiveRecord)
195
196
  require "graphiti/adapters/active_record"
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.7.7
4
+ version: 1.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-15 00:00:00.000000000 Z
11
+ date: 2025-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable
@@ -339,6 +339,7 @@ files:
339
339
  - lib/graphiti/util/sideload.rb
340
340
  - lib/graphiti/util/simple_errors.rb
341
341
  - lib/graphiti/util/transaction_hooks_recorder.rb
342
+ - lib/graphiti/util/uri_decoder.rb
342
343
  - lib/graphiti/util/validation_response.rb
343
344
  - lib/graphiti/version.rb
344
345
  - package.json