Class: ActiveShopifyGraphQL::Query::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shopify_graphql/query/node.rb,
lib/active_shopify_graphql/query/node/raw.rb,
lib/active_shopify_graphql/query/node/field.rb,
lib/active_shopify_graphql/query/node/fragment.rb,
lib/active_shopify_graphql/query/node/singular.rb,
lib/active_shopify_graphql/query/node/collection.rb,
lib/active_shopify_graphql/query/node/connection.rb,
lib/active_shopify_graphql/query/node/single_record.rb,
lib/active_shopify_graphql/query/node/root_connection.rb,
lib/active_shopify_graphql/query/node/current_customer.rb,
lib/active_shopify_graphql/query/node/nested_connection.rb

Overview

Abstract base class for all GraphQL query nodes. Provides shared attributes and helper methods for node rendering.

Subclasses:

- Node::Field - Simple and nested fields
- Node::Singular - Singular associations (has_one)
- Node::Connection - Collection associations using nodes pattern
- Node::Fragment - Fragment definitions
- Node::Raw - Raw GraphQL strings
- Node::SingleRecord - Single record queries by ID
- Node::CurrentCustomer - ID-less queries (Customer  API)
- Node::Collection - Collection queries with optional pagination
- Node::NestedConnection - Nested connection queries
- Node::RootConnection - Root-level connection queries

Defined Under Namespace

Classes: Collection, Connection, CurrentCustomer, Field, Fragment, NestedConnection, Raw, RootConnection, SingleRecord, Singular

Constant Summary collapse

PAGE_INFO_FIELDS =

Shared constants for query formatting

"pageInfo { hasNextPage hasPreviousPage startCursor endCursor }"
STRING_KEYS_NEEDING_QUOTES =
i[query after before].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, alias_name: nil, arguments: {}, children: []) ⇒ Node

Returns a new instance of Node.

Parameters:

  • name (String)

    The field name (e.g., 'id', 'displayName', 'orders')

  • alias_name (String) (defaults to: nil)

    Optional field alias (e.g., 'myAlias' for 'myAlias: fieldName')

  • arguments (Hash) (defaults to: {})

    Field arguments (e.g., { first: 10, sortKey: 'CREATED_AT' })

  • children (Array<Query::Node>) (defaults to: [])

    Child nodes for nested structures



29
30
31
32
33
34
# File 'lib/active_shopify_graphql/query/node.rb', line 29

def initialize(name:, alias_name: nil, arguments: {}, children: [])
  @name = name
  @alias_name = alias_name
  @arguments = arguments
  @children = children
end

Instance Attribute Details

#alias_nameObject (readonly)

Returns the value of attribute alias_name.



23
24
25
# File 'lib/active_shopify_graphql/query/node.rb', line 23

def alias_name
  @alias_name
end

#argumentsObject (readonly)

Returns the value of attribute arguments.



23
24
25
# File 'lib/active_shopify_graphql/query/node.rb', line 23

def arguments
  @arguments
end

#childrenObject (readonly)

Returns the value of attribute children.



23
24
25
# File 'lib/active_shopify_graphql/query/node.rb', line 23

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/active_shopify_graphql/query/node.rb', line 23

def name
  @name
end

Instance Method Details

#add_child(node) ⇒ Object

Add a child node



37
38
39
40
# File 'lib/active_shopify_graphql/query/node.rb', line 37

def add_child(node)
  @children << node
  node
end

#has_children?Boolean

Check if node has children

Returns:

  • (Boolean)


43
44
45
# File 'lib/active_shopify_graphql/query/node.rb', line 43

def has_children?
  @children.any?
end

#to_sObject

Convert node to GraphQL string - must be implemented by subclasses

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/active_shopify_graphql/query/node.rb', line 48

def to_s
  raise NotImplementedError, "#{self.class} must implement #to_s"
end