lib/graphql/client/schema/object_type.rb
# Given an AST selection on this object, gather it into `fields` if it applies.
# If it's a fragment, continue recursively checking the selections on the fragment.
Given an AST selection on this object, gather it into `fields` if it applies.
If it's a fragment, continue recursively checking the selections on the fragment.
Given an AST selection on this object gather it into ` fields ` if it applies . If it ' s a fragment continue recursively checking the selections on the fragment .
def gather_selections(fields, definition, selected_ast_node)
          case selected_ast_node
          when GraphQL::Language::Nodes::InlineFragment
            continue_selection = if selected_ast_node.type.nil?
              true
            else
              schema = definition.client.schema
              type_condition = schema.types[selected_ast_node.type.name]
              applicable_types = schema.possible_types(type_condition)
              applicable_types.include?(type)
            end
            if continue_selection
              selected_ast_node.selections.each do |next_selected_ast_node|
                gather_selections(fields, definition, next_selected_ast_node)
              end
            end
          when GraphQL::Language::Nodes::FragmentSpread
            fragment_definition = definition.document.definitions.find do |defn|
              defn.is_a?(GraphQL::Language::Nodes::FragmentDefinition) && defn.name == selected_ast_node.name
            end
            schema = definition.client.schema
            type_condition = schema.types[fragment_definition.type.name]
            applicable_types = schema.possible_types(type_condition)
            continue_selection = applicable_types.include?(type)
            if continue_selection
              fragment_definition.selections.each do |next_selected_ast_node|
                gather_selections(fields, definition, next_selected_ast_node)
              end
            end
          when GraphQL::Language::Nodes::Field
            operation_definition_for_field = definition.indexes[:definitions][selected_ast_node]
            if definition.source_document.definitions.include?(operation_definition_for_field)
              field_method_name = selected_ast_node.alias || selected_ast_node.name
              ast_nodes = fields[field_method_name] ||= []
              ast_nodes << selected_ast_node
            end
          else
            raise "Unexpected selection node: #{selected_ast_node}"
          end
        end
def gather_selections ( fields , definition , selected_ast_node ) case selected_ast_node when GraphQL :: Language :: Nodes :: InlineFragment continue_selection = if selected_ast_node . type . nil? true else schema = definition . client . schema type_condition = schema . types [ selected_ast_node . type . name ] applicable_types = schema . possible_types ( type_condition ) applicable_types . include? ( type ) end if continue_selection selected_ast_node . selections . each do | next_selected_ast_node | gather_selections ( fields , definition , next_selected_ast_node ) end end when GraphQL :: Language :: Nodes :: FragmentSpread fragment_definition = definition . document . definitions . find do | defn | defn . is_a? ( GraphQL :: Language :: Nodes :: FragmentDefinition ) && defn . name == selected_ast_node . name end schema = definition . client . schema type_condition = schema . types [ fragment_definition . type . name ] applicable_types = schema . possible_types ( type_condition ) continue_selection = applicable_types . include? ( type ) if continue_selection fragment_definition . selections . each do | next_selected_ast_node | gather_selections ( fields , definition , next_selected_ast_node ) end end when GraphQL :: Language :: Nodes :: Field operation_definition_for_field = definition . indexes [ :definitions ] [ selected_ast_node ] if definition . source_document . definitions . include? ( operation_definition_for_field ) field_method_name = selected_ast_node . alias || selected_ast_node . name ast_nodes = fields [ field_method_name ] ||= [ ] ast_nodes << selected_ast_node end else raise "Unexpected selection node: #{selected_ast_node}" end end
Given an AST selection on this object, gather it into `fields` if it applies.
Given an AST selection on this object gather it into ` fields ` if it applies .
# continue if this object type is one of the types matching the fragment condition # continue if this object type is one of the types matching the fragment condition # Ignore fields defined in other documents.
fields
<not_specific>
definition
<not_specific>
selected_ast_node
<not_specific>