Sha256: cd54c0720d6fbc1f5b9fcf533a5b02a752f7b24268e2c56ffc86cd25e6275287

Contents?: true

Size: 1.48 KB

Versions: 73

Compression:

Stored size: 1.48 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
          Thread.current[:last_graphql_backtrace_context] = push_data
        end

        if key == "execute_multiplex"
          begin
            yield
          rescue StandardError => err
            # This is an unhandled error from execution,
            # Re-raise it with a GraphQL trace.
            potential_context = Thread.current[:last_graphql_backtrace_context]

            if potential_context.is_a?(GraphQL::Query::Context) || potential_context.is_a?(GraphQL::Query::Context::FieldResolutionContext)
              raise TracedError.new(err, potential_context)
            else
              raise
            end
          ensure
            Thread.current[:last_graphql_backtrace_context] = nil
          end
        else
          yield
        end
      end
    end
  end
end

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
graphql-1.8.18 lib/graphql/backtrace/tracer.rb
graphql-1.11.4 lib/graphql/backtrace/tracer.rb
graphql-1.11.3 lib/graphql/backtrace/tracer.rb
graphql-1.11.2 lib/graphql/backtrace/tracer.rb
graphql-1.10.14 lib/graphql/backtrace/tracer.rb
graphql-1.11.1 lib/graphql/backtrace/tracer.rb
graphql-1.10.13 lib/graphql/backtrace/tracer.rb
graphql-1.11.0 lib/graphql/backtrace/tracer.rb
graphql-1.10.12 lib/graphql/backtrace/tracer.rb
graphql-1.9.21 lib/graphql/backtrace/tracer.rb
graphql-1.10.11 lib/graphql/backtrace/tracer.rb
graphql-1.9.20 lib/graphql/backtrace/tracer.rb
graphql-1.10.10 lib/graphql/backtrace/tracer.rb
graphql-1.10.9 lib/graphql/backtrace/tracer.rb
graphql-1.10.8 lib/graphql/backtrace/tracer.rb
graphql-1.10.7 lib/graphql/backtrace/tracer.rb
graphql-1.10.6 lib/graphql/backtrace/tracer.rb
graphql-1.10.5 lib/graphql/backtrace/tracer.rb
graphql-1.10.4 lib/graphql/backtrace/tracer.rb
graphql-1.10.3 lib/graphql/backtrace/tracer.rb