Class: GraphQL::Connection
Direct Known Subclasses
Class Attribute Summary collapse
-
.default_connection ⇒ Object
Returns the value of attribute default_connection.
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#syntax_fields ⇒ Object
readonly
Returns the value of attribute syntax_fields.
Attributes inherited from Node
Class Method Summary collapse
Instance Method Summary collapse
- #edge_fields ⇒ Object
- #edges ⇒ Object
-
#initialize(items, query:, fields: []) ⇒ Connection
constructor
A new instance of Connection.
- #items ⇒ Object
Methods inherited from Node
all_fields, #as_result, #context, cursor, desc, description, exposes, field, inherited, #method_missing, own_fields, remove_field, ruby_class_name, schema_name, type
Constructor Details
#initialize(items, query:, fields: []) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 |
# File 'lib/graphql/connection.rb', line 7 def initialize(items, query:, fields: []) @target = items @syntax_fields = fields @query = query end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class GraphQL::Node
Class Attribute Details
.default_connection ⇒ Object
Returns the value of attribute default_connection.
36 37 38 |
# File 'lib/graphql/connection.rb', line 36 def default_connection @default_connection end |
Instance Attribute Details
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
5 6 7 |
# File 'lib/graphql/connection.rb', line 5 def calls @calls end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
5 6 7 |
# File 'lib/graphql/connection.rb', line 5 def query @query end |
#syntax_fields ⇒ Object (readonly)
Returns the value of attribute syntax_fields.
5 6 7 |
# File 'lib/graphql/connection.rb', line 5 def syntax_fields @syntax_fields end |
Class Method Details
.default_connection! ⇒ Object
37 38 39 |
# File 'lib/graphql/connection.rb', line 37 def default_connection! GraphQL::Connection.default_connection = self end |
.default_schema_name ⇒ Object
32 33 34 |
# File 'lib/graphql/connection.rb', line 32 def default_schema_name name.split("::").last.sub(/Connection$/, '').underscore end |
Instance Method Details
#edge_fields ⇒ Object
17 18 19 |
# File 'lib/graphql/connection.rb', line 17 def edge_fields @edge_fields ||= syntax_fields.find { |f| f.identifier == "edges" }.fields end |
#edges ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/graphql/connection.rb', line 21 def edges raise "#{self.class} expected a connection, but got `nil`" if items.nil? items.map do |item| node_class = GraphQL::SCHEMA.type_for_object(item) node = node_class.new(item, fields: edge_fields, query: query) res = node.as_result res end end |
#items ⇒ Object
13 14 15 |
# File 'lib/graphql/connection.rb', line 13 def items @target end |