Skip to content

Commit 18f9104

Browse files
authored
Merge pull request #5318 from jocmp/master
Fix monitor trace suffix method
2 parents 5bc0a65 + 85b46f4 commit 18f9104

File tree

9 files changed

+244
-205
lines changed

9 files changed

+244
-205
lines changed

gemfiles/rails_master.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ gem 'selenium-webdriver'
2525

2626
gemspec path: "../"
2727

28-
if Bundler.settings["GEMS__GRAPHQL__PRO"]
28+
if (cred = Bundler.settings["GEMS__GRAPHQL__PRO"]) && !cred.empty?
2929
gem "graphql-pro", source: "https://gems.graphql.pro"
3030
gem "graphql-enterprise", source: "https://gems.graphql.pro"
3131
end

lib/graphql/tracing/monitor_trace.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ module GraphQLSuffixNames
9090
EXECUTE_NAME = "execute.graphql"
9191
ANALYZE_NAME = "analyze.graphql"
9292

93-
private
94-
9593
def platform_field_key(field)
9694
"#{field.path}.graphql"
9795
end
@@ -104,8 +102,8 @@ def platform_resolve_type_key(type)
104102
"#{type.graphql_name}.resolve_type.graphql"
105103
end
106104

107-
def platform_source_key(source_class)
108-
"#{source_class.name.gsub("::", "_").name.underscore}.fetch.graphql"
105+
def platform_source_class_key(source_class)
106+
"#{source_class.name.gsub("::", "_")}.fetch.graphql"
109107
end
110108
end
111109

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
# frozen_string_literal: true
22
require "test_helper"
33

4-
class DashboardLimitersLimitersControllerTest < ActionDispatch::IntegrationTest
5-
def test_it_checks_installed
6-
get graphql_dashboard.limiters_limiter_path("runtime", { schema: "GraphQL::Schema" })
7-
assert_includes response.body, CGI::escapeHTML("Rate limiters aren't installed on this schema yet.")
8-
refute_includes response.headers["Content-Security-Policy"], "nonce-"
9-
end
4+
if defined?(GraphQL::Pro)
5+
class DashboardLimitersLimitersControllerTest < ActionDispatch::IntegrationTest
6+
def test_it_checks_installed
7+
get graphql_dashboard.limiters_limiter_path("runtime", { schema: "GraphQL::Schema" })
8+
assert_includes response.body, CGI::escapeHTML("Rate limiters aren't installed on this schema yet.")
9+
refute_includes response.headers["Content-Security-Policy"], "nonce-"
10+
end
1011

11-
def test_it_shows_limiters
12-
Redis.new(db: DummySchema::DB_NUMBER).flushdb
12+
def test_it_shows_limiters
13+
Redis.new(db: DummySchema::DB_NUMBER).flushdb
1314

14-
3.times do
15-
DummySchema.execute("{ sleep(seconds: 0.02) }", context: { limiter_key: "client-1" }).to_h
16-
end
17-
4.times do
18-
DummySchema.execute("{ sleep(seconds: 0.110) }", context: { limiter_key: "client-2" }).to_h
19-
end
15+
3.times do
16+
DummySchema.execute("{ sleep(seconds: 0.02) }", context: { limiter_key: "client-1" }).to_h
17+
end
18+
4.times do
19+
DummySchema.execute("{ sleep(seconds: 0.110) }", context: { limiter_key: "client-2" }).to_h
20+
end
2021

21-
get graphql_dashboard.limiters_limiter_path("runtime")
22-
assert_includes response.body, "<span class=\"data\">4</span>"
23-
assert_includes response.body, "<span class=\"data\">3</span>"
24-
assert_includes response.body, "Disable Soft Limiting"
25-
assert_includes response.headers["Content-Security-Policy"], "nonce-"
22+
get graphql_dashboard.limiters_limiter_path("runtime")
23+
assert_includes response.body, "<span class=\"data\">4</span>"
24+
assert_includes response.body, "<span class=\"data\">3</span>"
25+
assert_includes response.body, "Disable Soft Limiting"
26+
assert_includes response.headers["Content-Security-Policy"], "nonce-"
2627

27-
patch graphql_dashboard.limiters_limiter_path("runtime")
28-
get graphql_dashboard.limiters_limiter_path("runtime")
29-
assert_includes response.body, "Enable Soft Limiting"
28+
patch graphql_dashboard.limiters_limiter_path("runtime")
29+
get graphql_dashboard.limiters_limiter_path("runtime")
30+
assert_includes response.body, "Enable Soft Limiting"
3031

31-
get graphql_dashboard.limiters_limiter_path("active_operations")
32-
assert_includes response.body, "It looks like this limiter isn't installed yet."
32+
get graphql_dashboard.limiters_limiter_path("active_operations")
33+
assert_includes response.body, "It looks like this limiter isn't installed yet."
3334

35+
end
3436
end
3537
end
Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,65 @@
11
# frozen_string_literal: true
22
require "test_helper"
33

4-
class DashboardOperationStoreClientsControllerTest < ActionDispatch::IntegrationTest
5-
def test_it_manages_clients
6-
assert_equal 0, DummySchema.operation_store.all_clients(page: 1, per_page: 1).total_count
7-
get graphql_dashboard.operation_store_clients_path
8-
assert_includes response.body, "0 Clients"
9-
assert_includes response.body, "To get started, create"
10-
11-
get graphql_dashboard.new_operation_store_client_path
12-
assert_includes response.body, "New Client"
13-
14-
post graphql_dashboard.operation_store_clients_path, params: {
15-
client: {
16-
name: "client-1",
17-
secret: "abcdefedcba"
18-
}
19-
}
4+
if defined?(GraphQL::Pro)
5+
class DashboardOperationStoreClientsControllerTest < ActionDispatch::IntegrationTest
6+
def test_it_manages_clients
7+
assert_equal 0, DummySchema.operation_store.all_clients(page: 1, per_page: 1).total_count
8+
get graphql_dashboard.operation_store_clients_path
9+
assert_includes response.body, "0 Clients"
10+
assert_includes response.body, "To get started, create"
2011

21-
get graphql_dashboard.operation_store_clients_path
22-
assert_includes response.body, "1 Client"
12+
get graphql_dashboard.new_operation_store_client_path
13+
assert_includes response.body, "New Client"
2314

24-
get graphql_dashboard.edit_operation_store_client_path(name: "client-1")
25-
assert_includes response.body, "abcdefedcba"
15+
post graphql_dashboard.operation_store_clients_path, params: {
16+
client: {
17+
name: "client-1",
18+
secret: "abcdefedcba"
19+
}
20+
}
2621

27-
patch graphql_dashboard.operation_store_client_path(name: "client-1"), params: { client: { secret: "123456789" } }
28-
get graphql_dashboard.edit_operation_store_client_path(name: "client-1")
29-
assert_includes response.body, "123456789"
22+
get graphql_dashboard.operation_store_clients_path
23+
assert_includes response.body, "1 Client"
3024

31-
delete graphql_dashboard.operation_store_client_path(name: "client-1")
32-
assert_equal 0, DummySchema.operation_store.all_clients(page: 1, per_page: 1).total_count
33-
ensure
34-
DummySchema.operation_store.delete_client("client-1")
35-
end
25+
get graphql_dashboard.edit_operation_store_client_path(name: "client-1")
26+
assert_includes response.body, "abcdefedcba"
3627

37-
def test_it_paginates
38-
5.times do |i|
39-
DummySchema.operation_store.upsert_client("client-#{i}", "abcdef")
28+
patch graphql_dashboard.operation_store_client_path(name: "client-1"), params: { client: { secret: "123456789" } }
29+
get graphql_dashboard.edit_operation_store_client_path(name: "client-1")
30+
assert_includes response.body, "123456789"
31+
32+
delete graphql_dashboard.operation_store_client_path(name: "client-1")
33+
assert_equal 0, DummySchema.operation_store.all_clients(page: 1, per_page: 1).total_count
34+
ensure
35+
DummySchema.operation_store.delete_client("client-1")
4036
end
41-
get graphql_dashboard.operation_store_clients_path(per_page: 2)
42-
assert_includes response.body, "5 Clients"
43-
assert_includes response.body, "?page=2&amp;per_page=2"
44-
assert_includes response.body, "disabled>« prev</button>"
45-
46-
get graphql_dashboard.operation_store_clients_path(per_page: 2, page: 2)
47-
assert_includes response.body, "?page=1&amp;per_page=2"
48-
assert_includes response.body, "?page=3&amp;per_page=2"
49-
50-
get graphql_dashboard.operation_store_clients_path(per_page: 2, page: 3)
51-
assert_includes response.body, "disabled>next »</button>"
52-
assert_includes response.body, "?page=2&amp;per_page=2"
53-
ensure
54-
5.times do |i|
55-
DummySchema.operation_store.delete_client("client-#{i}")
37+
38+
def test_it_paginates
39+
5.times do |i|
40+
DummySchema.operation_store.upsert_client("client-#{i}", "abcdef")
41+
end
42+
get graphql_dashboard.operation_store_clients_path(per_page: 2)
43+
assert_includes response.body, "5 Clients"
44+
assert_includes response.body, "?page=2&amp;per_page=2"
45+
assert_includes response.body, "disabled>« prev</button>"
46+
47+
get graphql_dashboard.operation_store_clients_path(per_page: 2, page: 2)
48+
assert_includes response.body, "?page=1&amp;per_page=2"
49+
assert_includes response.body, "?page=3&amp;per_page=2"
50+
51+
get graphql_dashboard.operation_store_clients_path(per_page: 2, page: 3)
52+
assert_includes response.body, "disabled>next »</button>"
53+
assert_includes response.body, "?page=2&amp;per_page=2"
54+
ensure
55+
5.times do |i|
56+
DummySchema.operation_store.delete_client("client-#{i}")
57+
end
5658
end
57-
end
5859

59-
def test_it_checks_installed
60-
get graphql_dashboard.new_operation_store_client_path, params: { schema: GraphQL::Schema }
61-
assert_includes response.body, "isn't installed for this schema yet"
60+
def test_it_checks_installed
61+
get graphql_dashboard.new_operation_store_client_path, params: { schema: GraphQL::Schema }
62+
assert_includes response.body, "isn't installed for this schema yet"
63+
end
6264
end
6365
end
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
# frozen_string_literal: true
22
require "test_helper"
33

4-
class DashboardOperationStoreIndexEntriesControllerTest < ActionDispatch::IntegrationTest
5-
def test_it_shows_entries
6-
DummySchema.operation_store.upsert_client("client-1", "abcdef")
7-
DummySchema.operation_store.add(body: "query GetTypename { __type(name: \"Query\") { name @skip(if: true) } }", operation_alias: "GetTypename", client_name: "client-1")
4+
if defined?(GraphQL::Pro)
5+
class DashboardOperationStoreIndexEntriesControllerTest < ActionDispatch::IntegrationTest
6+
def test_it_shows_entries
7+
DummySchema.operation_store.upsert_client("client-1", "abcdef")
8+
DummySchema.operation_store.add(body: "query GetTypename { __type(name: \"Query\") { name @skip(if: true) } }", operation_alias: "GetTypename", client_name: "client-1")
89

9-
get graphql_dashboard.operation_store_index_entries_path
10-
assert_includes response.body, "Query.__type.name"
11-
assert_includes response.body, "7 entries"
10+
get graphql_dashboard.operation_store_index_entries_path
11+
assert_includes response.body, "Query.__type.name"
12+
assert_includes response.body, "7 entries"
1213

13-
get graphql_dashboard.operation_store_index_entries_path(q: "Query")
14-
assert_includes response.body, "3 results"
15-
assert_includes response.body, ">Query</a>"
16-
assert_includes response.body, ">Query.__type</a>"
17-
assert_includes response.body, ">Query.__type.name</a>"
14+
get graphql_dashboard.operation_store_index_entries_path(q: "Query")
15+
assert_includes response.body, "3 results"
16+
assert_includes response.body, ">Query</a>"
17+
assert_includes response.body, ">Query.__type</a>"
18+
assert_includes response.body, ">Query.__type.name</a>"
1819

19-
get graphql_dashboard.operation_store_index_entries_path(q: "Query", per_page: 1, page: 2)
20-
assert_includes response.body, "3 results"
21-
refute_includes response.body, ">Query</a>"
22-
assert_includes response.body, ">Query.__type</a>"
23-
refute_includes response.body, ">Query.__type.name</a>"
20+
get graphql_dashboard.operation_store_index_entries_path(q: "Query", per_page: 1, page: 2)
21+
assert_includes response.body, "3 results"
22+
refute_includes response.body, ">Query</a>"
23+
assert_includes response.body, ">Query.__type</a>"
24+
refute_includes response.body, ">Query.__type.name</a>"
2425

25-
get graphql_dashboard.operation_store_index_entry_path(name: "Query.__type.name")
26-
assert_includes response.body, "GetTypename"
27-
ensure
28-
DummySchema.operation_store.delete_client("client-1")
26+
get graphql_dashboard.operation_store_index_entry_path(name: "Query.__type.name")
27+
assert_includes response.body, "GetTypename"
28+
ensure
29+
DummySchema.operation_store.delete_client("client-1")
30+
end
2931
end
3032
end

0 commit comments

Comments
 (0)