Class: ActiveShopifyGraphQL::LoaderContext

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shopify_graphql/loader_context.rb

Overview

Value object that encapsulates the shared context needed across query building, response mapping, and connection loading operations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graphql_type:, loader_class:, defined_attributes:, model_class:, included_connections: []) ⇒ LoaderContext

Returns a new instance of LoaderContext.



9
10
11
12
13
14
15
# File 'lib/active_shopify_graphql/loader_context.rb', line 9

def initialize(graphql_type:, loader_class:, defined_attributes:, model_class:, included_connections: [])
  @graphql_type = graphql_type
  @loader_class = loader_class
  @defined_attributes = defined_attributes
  @model_class = model_class
  @included_connections = Array(included_connections)
end

Instance Attribute Details

#defined_attributesObject (readonly)

Returns the value of attribute defined_attributes.



7
8
9
# File 'lib/active_shopify_graphql/loader_context.rb', line 7

def defined_attributes
  @defined_attributes
end

#graphql_typeObject (readonly)

Returns the value of attribute graphql_type.



7
8
9
# File 'lib/active_shopify_graphql/loader_context.rb', line 7

def graphql_type
  @graphql_type
end

#included_connectionsObject (readonly)

Returns the value of attribute included_connections.



7
8
9
# File 'lib/active_shopify_graphql/loader_context.rb', line 7

def included_connections
  @included_connections
end

#loader_classObject (readonly)

Returns the value of attribute loader_class.



7
8
9
# File 'lib/active_shopify_graphql/loader_context.rb', line 7

def loader_class
  @loader_class
end

#model_classObject (readonly)

Returns the value of attribute model_class.



7
8
9
# File 'lib/active_shopify_graphql/loader_context.rb', line 7

def model_class
  @model_class
end

Instance Method Details

#connectionsObject



37
38
39
40
41
# File 'lib/active_shopify_graphql/loader_context.rb', line 37

def connections
  return {} unless model_class

  model_class.connections
end

#for_model(new_model_class, new_graphql_type: nil, new_attributes: nil, new_connections: []) ⇒ Object

Create a new context for a different model (for connection targets)



18
19
20
21
22
23
24
25
26
# File 'lib/active_shopify_graphql/loader_context.rb', line 18

def for_model(new_model_class, new_graphql_type: nil, new_attributes: nil, new_connections: [])
  self.class.new(
    graphql_type: new_graphql_type || new_model_class.graphql_type_for_loader(loader_class),
    loader_class: loader_class,
    defined_attributes: new_attributes || new_model_class.attributes_for_loader(loader_class),
    model_class: new_model_class,
    included_connections: new_connections
  )
end

#fragment_nameObject



33
34
35
# File 'lib/active_shopify_graphql/loader_context.rb', line 33

def fragment_name
  "#{graphql_type}Fragment"
end

#query_nameObject

Helper methods delegated from context



29
30
31
# File 'lib/active_shopify_graphql/loader_context.rb', line 29

def query_name
  graphql_type.camelize(:lower)
end