Sha256: 9e84ed2e11ee7a174ef5d3e586ed1ab06652dd8e0b62061ef969e7df80a7f377

Contents?: true

Size: 1.67 KB

Versions: 77

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true
module GraphQL
  module Execution
    # Execute multiple queries under the same multiplex "umbrella".
    # They can share a batching context and reduce redundant database hits.
    #
    # The flow is:
    #
    # - Multiplex instrumentation setup
    # - Query instrumentation setup
    # - Analyze the multiplex + each query
    # - Begin each query
    # - Resolve lazy values, breadth-first across all queries
    # - Finish each query (eg, get errors)
    # - Query instrumentation teardown
    # - Multiplex instrumentation teardown
    #
    # If one query raises an application error, all queries will be in undefined states.
    #
    # Validation errors and {GraphQL::ExecutionError}s are handled in isolation:
    # one of these errors in one query will not affect the other queries.
    #
    # @see {Schema#multiplex} for public API
    # @api private
    class Multiplex
      include Tracing::Traceable

      attr_reader :context, :queries, :schema, :max_complexity, :dataloader, :current_trace

      def initialize(schema:, queries:, context:, max_complexity:)
        @schema = schema
        @queries = queries
        @queries.each { |q| q.multiplex = self }
        @context = context
        @current_trace = @context[:trace] || schema.new_trace(multiplex: self)
        @dataloader = @context[:dataloader] ||= @schema.dataloader_class.new
        @tracers = schema.tracers + (context[:tracers] || [])
        # Support `context: {backtrace: true}`
        if context[:backtrace] && !@tracers.include?(GraphQL::Backtrace::Tracer)
          @tracers << GraphQL::Backtrace::Tracer
        end
        @max_complexity = max_complexity
      end
    end
  end
end

Version data entries

77 entries across 77 versions & 1 rubygems

Version Path
graphql-2.3.22 lib/graphql/execution/multiplex.rb
graphql-2.1.15 lib/graphql/execution/multiplex.rb
graphql-2.0.32 lib/graphql/execution/multiplex.rb
graphql-2.1.14 lib/graphql/execution/multiplex.rb
graphql-2.2.17 lib/graphql/execution/multiplex.rb
graphql-2.3.21 lib/graphql/execution/multiplex.rb
graphql-2.4.8 lib/graphql/execution/multiplex.rb
graphql-2.4.7 lib/graphql/execution/multiplex.rb
graphql-2.4.6 lib/graphql/execution/multiplex.rb
graphql-2.4.5 lib/graphql/execution/multiplex.rb
graphql-2.4.4 lib/graphql/execution/multiplex.rb
graphql-2.4.3 lib/graphql/execution/multiplex.rb
graphql-2.4.2 lib/graphql/execution/multiplex.rb
graphql-2.4.1 lib/graphql/execution/multiplex.rb
graphql-2.4.0 lib/graphql/execution/multiplex.rb
graphql-2.3.20 lib/graphql/execution/multiplex.rb
graphql-2.3.19 lib/graphql/execution/multiplex.rb
graphql-2.3.18 lib/graphql/execution/multiplex.rb
graphql-2.3.17 lib/graphql/execution/multiplex.rb
graphql-2.3.16 lib/graphql/execution/multiplex.rb