Sha256: 01bc3ad1dec92a530775c1cf1749d8e3ad55e39e278b88f4ef784ff1c54afaad

Contents?: true

Size: 1.74 KB

Versions: 16

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Tracing::ActiveSupportNotificationsTracing do
  let(:schema) {
    StarWars::Schema.redefine {
      tracer GraphQL::Tracing::ActiveSupportNotificationsTracing
    }
  }

  it "pushes through AS::N" do
    traces = []

    callback = ->(name, started, finished, id, data) {
      path_str = if data.key?(:field)
        " (#{data[:field].path})"
      elsif data.key?(:context)
        " (#{data[:context].irep_node.owner_type}.#{data[:context].field.name})"
      else
        ""
      end
      traces << "#{name}#{path_str}"
    }

    query_string = <<-GRAPHQL
    query Bases($id1: ID!, $id2: ID!){
      b1: batchedBase(id: $id1) { name }
      b2: batchedBase(id: $id2) { name }
    }
    GRAPHQL
    first_id = StarWars::Base.first.id
    last_id = StarWars::Base.last.id

    ActiveSupport::Notifications.subscribed(callback, /^graphql/) do
      schema.execute(query_string, variables: {
        "id1" => first_id,
        "id2" => last_id,
      })
    end

    expected_traces = [
      "graphql.lex",
      "graphql.parse",
      "graphql.validate",
      "graphql.analyze_query",
      "graphql.analyze_multiplex",
      "graphql.execute_field (Query.batchedBase)",
      "graphql.execute_field (Query.batchedBase)",
      "graphql.execute_query",
      "graphql.lazy_loader",
      "graphql.execute_field_lazy (Query.batchedBase)",
      "graphql.execute_field (Base.name)",
      "graphql.execute_field_lazy (Query.batchedBase)",
      "graphql.execute_field (Base.name)",
      "graphql.execute_field_lazy (Base.name)",
      "graphql.execute_field_lazy (Base.name)",
      "graphql.execute_query_lazy",
      "graphql.execute_multiplex",
    ]
    assert_equal expected_traces, traces
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
graphql-1.9.11 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.10 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.9 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.8 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.7 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.6 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.5 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.4 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.3 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.2 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.1 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.0 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.0.pre4 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.0.pre3 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.0.pre2 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb
graphql-1.9.0.pre1 spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb