active_shopify_graphql 0.5.1 → 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: bfcae985a03d79f8f96eb49bebceb473b30f74beb3345eaee50e4b855bd025a2
4
- data.tar.gz: d10731edbeae0fddb323dbb7a4151a0da7e2ede0c717d64f65e0a721cc49e9e8
3
+ metadata.gz: e31c1e3cd47c1a256fa09dd9cc1457a227c8773f372d97156a0a3d7fb1ed1a78
4
+ data.tar.gz: 84ede826d98ae8dab30c59808bff5275702ff547225c12e053b4330e262c6675
5
5
  SHA512:
6
- metadata.gz: 23418843999e4908113a33af0bed8c9777f2d422067e48a2f333763dfc38ea16b04c746f347204193222fed27b0496311fe845e7faebb62fc0e87a66db131af4
7
- data.tar.gz: 810bae03627d5705cd6a00927b3aa1d6b40c75dc1b7da6fe3dc8c763e1c07c9e399b671c4c4fcfa61bd44e150e6f6de48afafeab0b591a9cc441e9f9f7010570
6
+ metadata.gz: 8294f6fb6de67eec0843aaf85a86692da10724ceb0bfe1aaff9a8bd4a53260ce3a917fc834822466e3e0df3b0d1e3bdc62f299e2b5c7277c08a97a357c7c5114
7
+ data.tar.gz: fa1ef4907d94c0415b1fc479aa85027a7dcc15a96123f625bb20e3eb331f9ce42a519ebdf84aeb4007911c81ec6719f3f32a9a8e6bf7e9e8f75f3816f89442e5
@@ -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.1"
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.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolò Rebughini