active_shopify_graphql 0.5.0 → 0.5.2

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: 3044e5a4ac6255ea55f7d10e48b0fe9a65825f813712f0cdc14e5993437e24bf
4
- data.tar.gz: f6b9e14fe814887bf0af4b90c174088f7c912ead322cb353fd84a95b2c4799e2
3
+ metadata.gz: e31c1e3cd47c1a256fa09dd9cc1457a227c8773f372d97156a0a3d7fb1ed1a78
4
+ data.tar.gz: 84ede826d98ae8dab30c59808bff5275702ff547225c12e053b4330e262c6675
5
5
  SHA512:
6
- metadata.gz: d5b38dbe06885fc9783e0f0980f1c690ad0a3edc0355f379bff6c0277eb0d69c76c07824d31295a020272b648ee8cd90c812e7399c75dc629650a9681df04b2f
7
- data.tar.gz: 6bdfb30c5888e3532cd19325769d460470c044d5db9c47ebf4b52bec368e8baaccfc65660d2696e04f978bf3d5d178e15a914718925a82b08f655fea8a3d25bf
6
+ metadata.gz: 8294f6fb6de67eec0843aaf85a86692da10724ceb0bfe1aaff9a8bd4a53260ce3a917fc834822466e3e0df3b0d1e3bdc62f299e2b5c7277c08a97a357c7c5114
7
+ data.tar.gz: fa1ef4907d94c0415b1fc479aa85027a7dcc15a96123f625bb20e3eb331f9ce42a519ebdf84aeb4007911c81ec6719f3f32a9a8e6bf7e9e8f75f3816f89442e5
@@ -19,10 +19,17 @@ module ActiveShopifyGraphQL::Model::Attributes
19
19
 
20
20
  if @current_loader_context
21
21
  # Store in loader-specific context
22
+ @loader_contexts ||= {}
23
+ @loader_contexts[@current_loader_context] ||= {}
22
24
  @loader_contexts[@current_loader_context][name] = config
23
25
  else
24
- # Store in base attributes
25
- @base_attributes ||= {}
26
+ # Store in base attributes, inheriting from parent if needed
27
+ @base_attributes ||=
28
+ if superclass.instance_variable_defined?(:@base_attributes)
29
+ superclass.instance_variable_get(:@base_attributes).dup
30
+ else
31
+ {}
32
+ end
26
33
  @base_attributes[name] = config
27
34
  end
28
35
 
@@ -6,7 +6,13 @@ module ActiveShopifyGraphQL::Model::Connections
6
6
  included do
7
7
  class << self
8
8
  def connections
9
- @connections ||= {}
9
+ # Inherit connections from parent class if it responds to connections
10
+ @connections ||=
11
+ if superclass.respond_to?(:connections)
12
+ superclass.connections.dup
13
+ else
14
+ {}
15
+ end
10
16
  end
11
17
 
12
18
  attr_writer :connections
@@ -11,11 +11,13 @@ module ActiveShopifyGraphQL::Model::FinderMethods
11
11
  end
12
12
 
13
13
  # Find a single record by ID
14
- # @param id [String, Integer] The record ID (will be converted to GID automatically)
14
+ # For Customer Account API, if no ID is provided, fetches the current customer
15
+ # @param id [String, Integer, nil] The record ID (will be converted to GID automatically)
15
16
  # @param loader [ActiveShopifyGraphQL::Loader] The loader to use for fetching data (deprecated, use Relation chain)
16
17
  # @return [Object] The model instance
17
18
  # @raise [ActiveShopifyGraphQL::ObjectNotFoundError] If the record is not found
18
- def find(id)
19
+ # @raise [ArgumentError] If id is nil and not using Customer Account API loader
20
+ def find(id = nil)
19
21
  all.find(id)
20
22
  end
21
23
 
@@ -75,10 +75,23 @@ module ActiveShopifyGraphQL
75
75
  end
76
76
 
77
77
  # Find a single record by ID
78
- # @param id [String, Integer] The record ID
78
+ # For Customer Account API, if no ID is provided, fetches the current customer
79
+ # @param id [String, Integer, nil] The record ID (will be converted to GID automatically)
79
80
  # @return [Object] The model instance
80
81
  # @raise [ObjectNotFoundError] If the record is not found
81
- def find(id)
82
+ # @raise [ArgumentError] If id is nil and not using Customer Account API loader
83
+ def find(id = nil)
84
+ # Handle Customer Account API case where no ID means "current customer"
85
+ if id.nil?
86
+ raise ArgumentError, "find requires an ID argument unless using Customer Account API" unless loader.is_a?(ActiveShopifyGraphQL::Loaders::CustomerAccountApiLoader)
87
+
88
+ attributes = loader.load_attributes
89
+ raise ObjectNotFoundError, "Couldn't find current customer" if attributes.nil?
90
+
91
+ return ModelBuilder.build(@model_class, attributes)
92
+ end
93
+
94
+ # Standard case: find by ID
82
95
  gid = GidHelper.normalize_gid(id, @model_class.model_name.name.demodulize)
83
96
  attributes = loader.load_attributes(gid)
84
97
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveShopifyGraphQL
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_shopify_graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolò Rebughini