Sha256: cc6515544d08e8e2706874c867a81c0bb1398cc1c93aca257062205b76892171

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true
module GraphQL
  class Backtrace
    module Tracer
      module_function

      # Implement the {GraphQL::Tracing} API.
      def trace(key, metadata)
        push_data = case key
        when "lex", "parse"
          # No context here, don't have a query yet
          nil
        when "execute_multiplex", "analyze_multiplex"
          metadata[:multiplex].queries
        when "validate", "analyze_query", "execute_query", "execute_query_lazy"
          metadata[:query] || metadata[:queries]
        when "execute_field", "execute_field_lazy"
          metadata[:context]
        else
          # Custom key, no backtrace data for this
          nil
        end

        if push_data
          execution_context = Thread.current[:graphql_execution_context] ||= []
          if key == "execute_multiplex"
            execution_context.clear
            execution_context.push(push_data)
            begin
              yield
            rescue StandardError => err
              # This is an unhandled error from execution,
              # Re-raise it with a GraphQL trace.
              raise TracedError.new(err, execution_context.last)
            ensure
              execution_context.clear
            end
          else
            execution_context.push(push_data)
            res = yield
            execution_context.pop
            res
          end
        else
          yield
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
graphql-1.7.4 lib/graphql/backtrace/tracer.rb
graphql-1.7.3 lib/graphql/backtrace/tracer.rb
graphql-1.7.2 lib/graphql/backtrace/tracer.rb
graphql-1.7.1 lib/graphql/backtrace/tracer.rb
graphql-1.7.0 lib/graphql/backtrace/tracer.rb