Class: ActiveShopifyGraphQL::Loaders::CustomerAccountApiLoader

Inherits:
ActiveShopifyGraphQL::Loader show all
Defined in:
lib/active_shopify_graphql/loaders/customer_account_api_loader.rb

Instance Method Summary collapse

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_argsObject



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

Raises:



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.
  raise Error, "Customer Account API executor not configured. Please configure it using ActiveShopifyGraphQL.configure" unless executor

  executor.call(query, @token, **variables)
end