Sha256: 552b42f676dbebb8a0ebda7c3796df0f59872f2ce47307b3cb16bbc83aaeda6b

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

module GraphQL
  class Query
    class SerialExecution
      class SelectionResolution
        attr_reader :target, :type, :irep_node, :execution_context

        def initialize(target, type, irep_node, execution_context)
          @target = target
          @type = type
          @irep_node = irep_node
          @execution_context = execution_context
        end

        def result
          irep_node.children.each_with_object({}) do |(name, irep_node), memo|
            if included_by_directives?(irep_node, execution_context.query) && applies_to_type?(irep_node, type, target)
              field_result = execution_context.strategy.field_resolution.new(
                irep_node,
                type,
                target,
                execution_context
              ).result
              memo.merge!(field_result)
            end
          end
        end

        private

        def included_by_directives?(irep_node, query)
          GraphQL::Query::DirectiveResolution.include_node?(irep_node, query)
        end

        def applies_to_type?(irep_node, type, target)
          irep_node.definitions.any? { |child_type, field_defn|
            GraphQL::Query::TypeResolver.new(target, child_type, type, execution_context.query.context).type
          }
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
graphql-0.18.1 lib/graphql/query/serial_execution/selection_resolution.rb
graphql-0.18.0 lib/graphql/query/serial_execution/selection_resolution.rb
graphql-0.17.2 lib/graphql/query/serial_execution/selection_resolution.rb
graphql-0.17.1 lib/graphql/query/serial_execution/selection_resolution.rb
graphql-0.17.0 lib/graphql/query/serial_execution/selection_resolution.rb