Class: GraphQL::Client::Query::SelectionSet

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_client/query/selection_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSelectionSet

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

#fieldsObject (readonly)

Returns the value of attribute fields.



7
8
9
# File 'lib/graphql_client/query/selection_set.rb', line 7

def fields
  @fields
end

#fragmentsObject (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_fragmentsObject (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

Returns:

  • (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

Returns:

  • (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

#selectionsObject



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