Class: ActiveShopifyGraphQL::Loaders::CustomerAccountApiLoader
- Inherits:
-
ActiveShopifyGraphQL::Loader
- Object
- ActiveShopifyGraphQL::Loader
- ActiveShopifyGraphQL::Loaders::CustomerAccountApiLoader
- Defined in:
- lib/active_shopify_graphql/loaders/customer_account_api_loader.rb
Instance Method Summary collapse
- #initialization_args ⇒ Object
-
#initialize(model_class = nil, token = nil, selected_attributes: nil, included_connections: nil) ⇒ CustomerAccountApiLoader
constructor
A new instance of CustomerAccountApiLoader.
-
#load_attributes(id = nil) ⇒ Object
Override load_attributes to handle the Customer case.
- #perform_graphql_query(query, **variables) ⇒ Object
Methods inherited from ActiveShopifyGraphQL::Loader
#context, #defined_attributes, #execute_query, #has_included_connections?, #load_connection_records, #load_paginated_collection, #map_response_to_attributes
Constructor Details
#initialize(model_class = nil, token = nil, selected_attributes: nil, included_connections: nil) ⇒ CustomerAccountApiLoader
Returns a new instance of CustomerAccountApiLoader.
6 7 8 9 |
# File 'lib/active_shopify_graphql/loaders/customer_account_api_loader.rb', line 6 def initialize(model_class = nil, token = nil, selected_attributes: nil, included_connections: nil) super(model_class, selected_attributes: selected_attributes, included_connections: included_connections) @token = token end |
Instance Method Details
#initialization_args ⇒ Object
33 34 35 |
# File 'lib/active_shopify_graphql/loaders/customer_account_api_loader.rb', line 33 def initialization_args [@token] end |
#load_attributes(id = nil) ⇒ Object
Override load_attributes to handle the Customer case
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_shopify_graphql/loaders/customer_account_api_loader.rb', line 12 def load_attributes(id = nil) query = if context.graphql_type == 'Customer' Query::QueryBuilder.build_current_customer_query(context) else Query::QueryBuilder.build_single_record_query(context) end variables = context.graphql_type == 'Customer' ? {} : { id: id } response_data = execute_query(query, **variables) return nil if response_data.nil? map_response_to_attributes(response_data) end |
#perform_graphql_query(query, **variables) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/active_shopify_graphql/loaders/customer_account_api_loader.rb', line 26 def perform_graphql_query(query, **variables) executor = ActiveShopifyGraphQL.configuration.customer_account_api_executor raise Error, "Customer Account API executor not configured. Please configure it using ActiveShopifyGraphQL.configure" unless executor executor.call(query, @token, **variables) end |