Class: GraphQL::Client::Query::Field
- Inherits:
-
Object
- Object
- GraphQL::Client::Query::Field
- Includes:
- AddInlineFragment, HasSelectionSet
- Defined in:
- lib/graphql_client/query/field.rb
Constant Summary collapse
- INVALID_ARGUMENTS =
Class.new(StandardError)
Constants included from HasSelectionSet
HasSelectionSet::ID_FIELD_NAME, HasSelectionSet::INVALID_FIELD, HasSelectionSet::UNDEFINED_FRAGMENT
Constants included from AddInlineFragment
AddInlineFragment::INVALID_FRAGMENT_TARGET
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#as ⇒ Object
readonly
Returns the value of attribute as.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#field_defn ⇒ Object
readonly
Returns the value of attribute field_defn.
Attributes included from HasSelectionSet
Instance Method Summary collapse
- #add_arguments(**arguments) ⇒ Object
- #aliased? ⇒ Boolean
- #connection? ⇒ Boolean
-
#initialize(field_defn, document:, arguments: {}, as: nil) ⇒ Field
constructor
A new instance of Field.
- #name ⇒ Object
- #node? ⇒ Boolean
- #resolver_type ⇒ Object
- #schema ⇒ Object
- #to_query(indent: '') ⇒ Object (also: #to_s)
Methods included from HasSelectionSet
#add_connection, #add_field, #add_fields, #add_fragment
Methods included from AddInlineFragment
Constructor Details
#initialize(field_defn, document:, arguments: {}, as: nil) ⇒ Field
Returns a new instance of Field.
14 15 16 17 18 19 20 |
# File 'lib/graphql_client/query/field.rb', line 14 def initialize(field_defn, document:, arguments: {}, as: nil) @field_defn = field_defn @document = document @arguments = validate_arguments(arguments) @as = as @selection_set = SelectionSet.new end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
12 13 14 |
# File 'lib/graphql_client/query/field.rb', line 12 def arguments @arguments end |
#as ⇒ Object (readonly)
Returns the value of attribute as.
12 13 14 |
# File 'lib/graphql_client/query/field.rb', line 12 def as @as end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
12 13 14 |
# File 'lib/graphql_client/query/field.rb', line 12 def document @document end |
#field_defn ⇒ Object (readonly)
Returns the value of attribute field_defn.
12 13 14 |
# File 'lib/graphql_client/query/field.rb', line 12 def field_defn @field_defn end |
Instance Method Details
#add_arguments(**arguments) ⇒ Object
22 23 24 25 |
# File 'lib/graphql_client/query/field.rb', line 22 def add_arguments(**arguments) new_arguments = validate_arguments(arguments) @arguments.merge!(new_arguments) end |
#aliased? ⇒ Boolean
27 28 29 |
# File 'lib/graphql_client/query/field.rb', line 27 def aliased? name != field_defn.name end |
#connection? ⇒ Boolean
35 36 37 |
# File 'lib/graphql_client/query/field.rb', line 35 def connection? resolver_type.name.to_s.end_with?('Connection') end |
#name ⇒ Object
39 40 41 |
# File 'lib/graphql_client/query/field.rb', line 39 def name as || field_defn.name end |
#node? ⇒ Boolean
43 44 45 |
# File 'lib/graphql_client/query/field.rb', line 43 def node? field_defn.name == 'Node' || (resolver_type.object? && resolver_type.implement?('Node')) end |
#resolver_type ⇒ Object
47 48 49 |
# File 'lib/graphql_client/query/field.rb', line 47 def resolver_type @resolver_type ||= schema.type(field_defn.type.unwrap.name) end |
#schema ⇒ Object
51 52 53 |
# File 'lib/graphql_client/query/field.rb', line 51 def schema document.schema end |
#to_query(indent: '') ⇒ Object Also known as: to_s
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/graphql_client/query/field.rb', line 55 def to_query(indent: '') indent.dup.tap do |query_string| query_string << "#{as}: " if aliased? query_string << field_defn.name query_string << "(#{arguments_string.join(', ')})" if arguments.any? unless selection_set.empty? query_string << " {\n" query_string << selection_set.to_query(indent) query_string << "\n#{indent}}" end end end |