Class: ElasticGraph::GraphQL::Resolvers::RelayConnection::ArrayAdapter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/elastic_graph/graphql/resolvers/relay_connection/array_adapter.rb

Overview

Relay connection adapter for an array. Implemented primarily by ‘GraphQL::Relay::ArrayConnection`; here we just adapt it to the ElasticGraph internal resolver interface.

Defined Under Namespace

Classes: Edge

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(nodes, args, schema_element_names, context) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/elastic_graph/graphql/resolvers/relay_connection/array_adapter.rb', line 27

def self.build(nodes, args, schema_element_names, context)
  # ElasticGraph supports any schema elements (like a `first` argument) being renamed,
  # but `GraphQL::Relay::ArrayConnection` would not understand a renamed argument.
  # Here we map the args back to the canonical relay args so `ArrayConnection` can
  # understand them.
  relay_args = [:first, :after, :last, :before].to_h do |arg_name|
    [arg_name, args[schema_element_names.public_send(arg_name)]]
  end.compact

  graphql_impl = ::GraphQL::Pagination::ArrayConnection.new(nodes || [], context: context, **relay_args)
  new(schema_element_names, graphql_impl)
end

Instance Method Details

#edgesObject



48
49
50
51
52
# File 'lib/elastic_graph/graphql/resolvers/relay_connection/array_adapter.rb', line 48

def edges
  @edges ||= graphql_impl.nodes.map do |node|
    Edge.new(schema_element_names, graphql_impl, node)
  end
end

#nodesObject



54
55
56
# File 'lib/elastic_graph/graphql/resolvers/relay_connection/array_adapter.rb', line 54

def nodes
  @nodes ||= graphql_impl.nodes
end

#page_infoObject



44
45
46
# File 'lib/elastic_graph/graphql/resolvers/relay_connection/array_adapter.rb', line 44

def page_info
  self
end

#total_edge_countObject



40
41
42
# File 'lib/elastic_graph/graphql/resolvers/relay_connection/array_adapter.rb', line 40

def total_edge_count
  graphql_impl.nodes.size
end