Class: ActiveShopifyGraphQL::Query::Node::Collection

Inherits:
ActiveShopifyGraphQL::Query::Node show all
Defined in:
lib/active_shopify_graphql/query/node/collection.rb

Overview

Renders a collection query with optional pagination. Example without pagination:

query getCustomers {
customers(first: 10) {
  nodes {
    ...CustomerFragment
  }
}
}

Example with pagination:

query getCustomers {
customers(first: 10, after: "cursor") {
  pageInfo {
    hasNextPage
    hasPreviousPage
    startCursor
    endCursor
  }
  nodes {
    ...CustomerFragment
  }
}
}

Constant Summary

Constants inherited from ActiveShopifyGraphQL::Query::Node

PAGE_INFO_FIELDS, STRING_KEYS_NEEDING_QUOTES

Instance Attribute Summary collapse

Attributes inherited from ActiveShopifyGraphQL::Query::Node

#alias_name, #arguments, #children, #name

Instance Method Summary collapse

Methods inherited from ActiveShopifyGraphQL::Query::Node

#add_child, #has_children?

Constructor Details

#initialize(model_type:, query_name:, fragment_name:, variables: {}, fragments: [], include_page_info: false) ⇒ Collection

Returns a new instance of Collection.



33
34
35
36
37
38
39
40
41
# File 'lib/active_shopify_graphql/query/node/collection.rb', line 33

def initialize(model_type:, query_name:, fragment_name:, variables: {}, fragments: [], include_page_info: false)
  @model_type = model_type
  @query_name = query_name
  @fragment_name = fragment_name
  @variables = variables
  @fragments = fragments
  @include_page_info = include_page_info
  super(name: query_name)
end

Instance Attribute Details

#fragment_nameObject (readonly)

Returns the value of attribute fragment_name.



31
32
33
# File 'lib/active_shopify_graphql/query/node/collection.rb', line 31

def fragment_name
  @fragment_name
end

#fragmentsObject (readonly)

Returns the value of attribute fragments.



31
32
33
# File 'lib/active_shopify_graphql/query/node/collection.rb', line 31

def fragments
  @fragments
end

#include_page_infoObject (readonly)

Returns the value of attribute include_page_info.



31
32
33
# File 'lib/active_shopify_graphql/query/node/collection.rb', line 31

def include_page_info
  @include_page_info
end

#model_typeObject (readonly)

Returns the value of attribute model_type.



31
32
33
# File 'lib/active_shopify_graphql/query/node/collection.rb', line 31

def model_type
  @model_type
end

#query_nameObject (readonly)

Returns the value of attribute query_name.



31
32
33
# File 'lib/active_shopify_graphql/query/node/collection.rb', line 31

def query_name
  @query_name
end

#variablesObject (readonly)

Returns the value of attribute variables.



31
32
33
# File 'lib/active_shopify_graphql/query/node/collection.rb', line 31

def variables
  @variables
end

Instance Method Details

#to_sObject



43
44
45
46
47
48
49
# File 'lib/active_shopify_graphql/query/node/collection.rb', line 43

def to_s
  parts = [fragments_string, "query get#{model_type.pluralize} { #{query_name}#{field_signature} {"]
  parts << PAGE_INFO_FIELDS if @include_page_info
  parts << "nodes { ...#{fragment_name} }"
  parts << "} }"
  parts.join(' ')
end