Class: GraphQL::Client::Query::SelectionSet
- Inherits:
-
Object
- Object
- GraphQL::Client::Query::SelectionSet
- Defined in:
- lib/graphql_client/query/selection_set.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#fragments ⇒ Object
readonly
Returns the value of attribute fragments.
-
#inline_fragments ⇒ Object
readonly
Returns the value of attribute inline_fragments.
Instance Method Summary collapse
- #add_field(field) ⇒ Object
- #add_fragment(fragment) ⇒ Object
- #add_inline_fragment(inline_fragment) ⇒ Object
- #contains?(field_name) ⇒ Boolean
- #empty? ⇒ Boolean
-
#initialize ⇒ SelectionSet
constructor
A new instance of SelectionSet.
- #lookup(name) ⇒ Object
- #selections ⇒ Object
- #to_query(indent = '') ⇒ Object (also: #to_s)
Constructor Details
#initialize ⇒ SelectionSet
Returns a new instance of SelectionSet.
9 10 11 12 13 |
# File 'lib/graphql_client/query/selection_set.rb', line 9 def initialize @fragments = {} @fields = {} @inline_fragments = [] end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
7 8 9 |
# File 'lib/graphql_client/query/selection_set.rb', line 7 def fields @fields end |
#fragments ⇒ Object (readonly)
Returns the value of attribute fragments.
7 8 9 |
# File 'lib/graphql_client/query/selection_set.rb', line 7 def fragments @fragments end |
#inline_fragments ⇒ Object (readonly)
Returns the value of attribute inline_fragments.
7 8 9 |
# File 'lib/graphql_client/query/selection_set.rb', line 7 def inline_fragments @inline_fragments end |
Instance Method Details
#add_field(field) ⇒ Object
15 16 17 |
# File 'lib/graphql_client/query/selection_set.rb', line 15 def add_field(field) @fields[field.name] = field end |
#add_fragment(fragment) ⇒ Object
19 20 21 |
# File 'lib/graphql_client/query/selection_set.rb', line 19 def add_fragment(fragment) @fragments[fragment.name] = fragment end |
#add_inline_fragment(inline_fragment) ⇒ Object
23 24 25 |
# File 'lib/graphql_client/query/selection_set.rb', line 23 def add_inline_fragment(inline_fragment) @inline_fragments << inline_fragment end |
#contains?(field_name) ⇒ Boolean
27 28 29 |
# File 'lib/graphql_client/query/selection_set.rb', line 27 def contains?(field_name) fields.key?(field_name) end |
#empty? ⇒ Boolean
31 32 33 |
# File 'lib/graphql_client/query/selection_set.rb', line 31 def empty? selections.empty? end |
#lookup(name) ⇒ Object
35 36 37 |
# File 'lib/graphql_client/query/selection_set.rb', line 35 def lookup(name) fields.fetch(name) end |
#selections ⇒ Object
39 40 41 |
# File 'lib/graphql_client/query/selection_set.rb', line 39 def selections fields.values + fragments.values + inline_fragments end |
#to_query(indent = '') ⇒ Object Also known as: to_s
43 44 45 46 47 |
# File 'lib/graphql_client/query/selection_set.rb', line 43 def to_query(indent = '') selections.map do |selection| selection.to_query(indent: indent + ' ') end.join("\n") end |