Class: ElasticGraph::GraphQL::Resolvers::RelayConnection::ArrayAdapter
- Inherits:
-
Object
- Object
- ElasticGraph::GraphQL::Resolvers::RelayConnection::ArrayAdapter
- 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, context) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/elastic_graph/graphql/resolvers/relay_connection/array_adapter.rb', line 28 def self.build(nodes, args, context) schema = context.fetch(:elastic_graph_schema) schema_element_names = schema.element_names nodes ||= [] # : ::Array[untyped] # 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. # # `after` and `before` are encoded to convert them to the string form required by `ArrayConnection`. relay_args = { first: args[schema_element_names.first], after: args[schema_element_names.after]&.encode, last: args[schema_element_names.last], before: args[schema_element_names.before]&.encode }.compact graphql_impl = ::GraphQL::Pagination::ArrayConnection.new(nodes, context: context, **relay_args) new(schema, graphql_impl, nodes.size) end |
Instance Method Details
#edges ⇒ Object
54 55 56 57 58 |
# File 'lib/elastic_graph/graphql/resolvers/relay_connection/array_adapter.rb', line 54 def edges @edges ||= graphql_impl.nodes.map do |node| Edge.new(schema, graphql_impl, node) end end |
#nodes ⇒ Object
60 61 62 |
# File 'lib/elastic_graph/graphql/resolvers/relay_connection/array_adapter.rb', line 60 def nodes @nodes ||= graphql_impl.nodes end |
#page_info ⇒ Object
50 51 52 |
# File 'lib/elastic_graph/graphql/resolvers/relay_connection/array_adapter.rb', line 50 def page_info self end |