graphql 1.9.7 → 1.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/install_generator.rb +2 -1
- data/lib/generators/graphql/templates/base_argument.erb +4 -0
- data/lib/generators/graphql/templates/base_field.erb +2 -0
- data/lib/generators/graphql/templates/base_input_object.erb +1 -0
- data/lib/graphql/analysis/ast/query_complexity.rb +34 -18
- data/lib/graphql/argument.rb +8 -2
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +1 -1
- data/lib/graphql/language/lexer.rb +24 -13
- data/lib/graphql/language/lexer.rl +23 -13
- data/lib/graphql/query/arguments.rb +16 -15
- data/lib/graphql/schema.rb +105 -48
- data/lib/graphql/schema/argument.rb +12 -1
- data/lib/graphql/schema/build_from_definition.rb +3 -0
- data/lib/graphql/schema/field.rb +3 -8
- data/lib/graphql/schema/find_inherited_value.rb +20 -0
- data/lib/graphql/schema/input_object.rb +1 -3
- data/lib/graphql/schema/loader.rb +1 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +7 -18
- data/lib/graphql/schema/member/has_arguments.rb +4 -9
- data/lib/graphql/schema/member/has_fields.rb +14 -0
- data/lib/graphql/schema/member/relay_shortcuts.rb +2 -2
- data/lib/graphql/schema/resolver.rb +31 -8
- data/lib/graphql/schema/resolver/has_payload_type.rb +3 -2
- data/lib/graphql/schema/subscription.rb +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/spec/graphql/analysis/analyze_query_spec.rb +14 -25
- data/spec/graphql/analysis/ast/max_query_complexity_spec.rb +7 -19
- data/spec/graphql/analysis/ast/max_query_depth_spec.rb +5 -12
- data/spec/graphql/analysis/max_query_complexity_spec.rb +12 -20
- data/spec/graphql/analysis/max_query_depth_spec.rb +6 -13
- data/spec/graphql/language/lexer_spec.rb +19 -1
- data/spec/graphql/schema/argument_spec.rb +1 -1
- data/spec/graphql/schema/build_from_definition_spec.rb +10 -0
- data/spec/graphql/schema/catchall_middleware_spec.rb +6 -9
- data/spec/graphql/schema/input_object_spec.rb +25 -0
- data/spec/graphql/schema/loader_spec.rb +65 -1
- data/spec/graphql/schema/object_spec.rb +21 -0
- data/spec/graphql/schema/resolver_spec.rb +30 -1
- data/spec/graphql/schema_spec.rb +135 -0
- data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +25 -0
- data/spec/integration/rails/generators/graphql/install_generator_spec.rb +20 -0
- data/spec/integration/tmp/app/graphql/types/page_type.rb +5 -0
- data/spec/support/dummy/schema.rb +1 -1
- data/spec/support/lazy_helpers.rb +1 -1
- data/spec/support/parser/filename_example_invalid_utf8.graphql +1 -0
- metadata +10 -132
- data/spec/integration/tmp/app/graphql/types/date_type.rb +0 -14
- data/spec/integration/tmp/dummy/Gemfile +0 -50
- data/spec/integration/tmp/dummy/README.md +0 -24
- data/spec/integration/tmp/dummy/Rakefile +0 -6
- data/spec/integration/tmp/dummy/app/assets/config/manifest.js +0 -3
- data/spec/integration/tmp/dummy/app/assets/javascripts/application.js +0 -16
- data/spec/integration/tmp/dummy/app/assets/javascripts/cable.js +0 -13
- data/spec/integration/tmp/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/integration/tmp/dummy/app/channels/application_cable/channel.rb +0 -5
- data/spec/integration/tmp/dummy/app/channels/application_cable/connection.rb +0 -5
- data/spec/integration/tmp/dummy/app/controllers/application_controller.rb +0 -4
- data/spec/integration/tmp/dummy/app/controllers/graphql_controller.rb +0 -44
- data/spec/integration/tmp/dummy/app/helpers/application_helper.rb +0 -3
- data/spec/integration/tmp/dummy/app/jobs/application_job.rb +0 -3
- data/spec/integration/tmp/dummy/app/mailers/application_mailer.rb +0 -5
- data/spec/integration/tmp/dummy/app/mydirectory/dummy_schema.rb +0 -5
- data/spec/integration/tmp/dummy/app/mydirectory/mutations/update_name.rb +0 -15
- data/spec/integration/tmp/dummy/app/mydirectory/types/base_enum.rb +0 -5
- data/spec/integration/tmp/dummy/app/mydirectory/types/base_input_object.rb +0 -5
- data/spec/integration/tmp/dummy/app/mydirectory/types/base_interface.rb +0 -6
- data/spec/integration/tmp/dummy/app/mydirectory/types/base_object.rb +0 -5
- data/spec/integration/tmp/dummy/app/mydirectory/types/base_scalar.rb +0 -5
- data/spec/integration/tmp/dummy/app/mydirectory/types/base_union.rb +0 -5
- data/spec/integration/tmp/dummy/app/mydirectory/types/mutation_type.rb +0 -12
- data/spec/integration/tmp/dummy/app/mydirectory/types/query_type.rb +0 -14
- data/spec/integration/tmp/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/integration/tmp/dummy/app/views/layouts/mailer.html.erb +0 -13
- data/spec/integration/tmp/dummy/app/views/layouts/mailer.text.erb +0 -1
- data/spec/integration/tmp/dummy/bin/bundle +0 -3
- data/spec/integration/tmp/dummy/bin/rails +0 -4
- data/spec/integration/tmp/dummy/bin/rake +0 -4
- data/spec/integration/tmp/dummy/bin/setup +0 -34
- data/spec/integration/tmp/dummy/bin/update +0 -29
- data/spec/integration/tmp/dummy/config.ru +0 -5
- data/spec/integration/tmp/dummy/config/application.rb +0 -26
- data/spec/integration/tmp/dummy/config/boot.rb +0 -4
- data/spec/integration/tmp/dummy/config/cable.yml +0 -9
- data/spec/integration/tmp/dummy/config/environment.rb +0 -6
- data/spec/integration/tmp/dummy/config/environments/development.rb +0 -52
- data/spec/integration/tmp/dummy/config/environments/production.rb +0 -84
- data/spec/integration/tmp/dummy/config/environments/test.rb +0 -43
- data/spec/integration/tmp/dummy/config/initializers/application_controller_renderer.rb +0 -9
- data/spec/integration/tmp/dummy/config/initializers/assets.rb +0 -12
- data/spec/integration/tmp/dummy/config/initializers/backtrace_silencers.rb +0 -8
- data/spec/integration/tmp/dummy/config/initializers/cookies_serializer.rb +0 -6
- data/spec/integration/tmp/dummy/config/initializers/filter_parameter_logging.rb +0 -5
- data/spec/integration/tmp/dummy/config/initializers/inflections.rb +0 -17
- data/spec/integration/tmp/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/integration/tmp/dummy/config/initializers/new_framework_defaults.rb +0 -24
- data/spec/integration/tmp/dummy/config/initializers/session_store.rb +0 -4
- data/spec/integration/tmp/dummy/config/initializers/wrap_parameters.rb +0 -10
- data/spec/integration/tmp/dummy/config/locales/en.yml +0 -23
- data/spec/integration/tmp/dummy/config/puma.rb +0 -48
- data/spec/integration/tmp/dummy/config/routes.rb +0 -9
- data/spec/integration/tmp/dummy/config/secrets.yml +0 -22
- data/spec/integration/tmp/dummy/db/seeds.rb +0 -8
- data/spec/integration/tmp/dummy/log/test.log +0 -0
- data/spec/integration/tmp/dummy/public/404.html +0 -67
- data/spec/integration/tmp/dummy/public/422.html +0 -67
- data/spec/integration/tmp/dummy/public/500.html +0 -66
- data/spec/integration/tmp/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/integration/tmp/dummy/public/apple-touch-icon.png +0 -0
- data/spec/integration/tmp/dummy/public/favicon.ico +0 -0
- data/spec/integration/tmp/dummy/public/robots.txt +0 -5
- data/spec/integration/tmp/dummy/test/test_helper.rb +0 -8
@@ -2,14 +2,7 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe GraphQL::Analysis::AST::MaxQueryComplexity do
|
5
|
-
|
6
|
-
@prev_max_complexity = Dummy::Schema.max_complexity
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
Dummy::Schema.max_complexity = @prev_max_complexity
|
11
|
-
end
|
12
|
-
|
5
|
+
let(:schema) { Class.new(Dummy::Schema) }
|
13
6
|
let(:query_string) {%|
|
14
7
|
{
|
15
8
|
a: cheese(id: 1) { id }
|
@@ -19,7 +12,7 @@ describe GraphQL::Analysis::AST::MaxQueryComplexity do
|
|
19
12
|
e: cheese(id: 1) { id }
|
20
13
|
}
|
21
14
|
|}
|
22
|
-
let(:query) { GraphQL::Query.new(
|
15
|
+
let(:query) { GraphQL::Query.new(schema, query_string, variables: {}, max_complexity: max_complexity) }
|
23
16
|
let(:result) {
|
24
17
|
GraphQL::Analysis::AST.analyze_query(query, [GraphQL::Analysis::AST::MaxQueryComplexity]).first
|
25
18
|
}
|
@@ -52,7 +45,7 @@ describe GraphQL::Analysis::AST::MaxQueryComplexity do
|
|
52
45
|
|
53
46
|
describe "when max_complexity is decreased at query-level" do
|
54
47
|
before do
|
55
|
-
|
48
|
+
schema.max_complexity = 100
|
56
49
|
end
|
57
50
|
|
58
51
|
let(:max_complexity) { 7 }
|
@@ -65,7 +58,7 @@ describe GraphQL::Analysis::AST::MaxQueryComplexity do
|
|
65
58
|
|
66
59
|
describe "when max_complexity is increased at query-level" do
|
67
60
|
before do
|
68
|
-
|
61
|
+
schema.max_complexity = 1
|
69
62
|
end
|
70
63
|
|
71
64
|
let(:max_complexity) { 10 }
|
@@ -77,22 +70,17 @@ describe GraphQL::Analysis::AST::MaxQueryComplexity do
|
|
77
70
|
|
78
71
|
describe "across a multiplex" do
|
79
72
|
before do
|
80
|
-
|
81
|
-
Dummy::Schema.analysis_engine = GraphQL::Analysis::AST
|
82
|
-
end
|
83
|
-
|
84
|
-
after do
|
85
|
-
Dummy::Schema.analysis_engine = @old_analysis_engine
|
73
|
+
schema.analysis_engine = GraphQL::Analysis::AST
|
86
74
|
end
|
87
75
|
|
88
76
|
let(:queries) {
|
89
77
|
5.times.map { |n|
|
90
|
-
GraphQL::Query.new(
|
78
|
+
GraphQL::Query.new(schema, "{ cheese(id: #{n}) { id } }", variables: {})
|
91
79
|
}
|
92
80
|
}
|
93
81
|
|
94
82
|
let(:max_complexity) { 9 }
|
95
|
-
let(:multiplex) { GraphQL::Execution::Multiplex.new(schema:
|
83
|
+
let(:multiplex) { GraphQL::Execution::Multiplex.new(schema: schema, queries: queries, context: {}, max_complexity: max_complexity) }
|
96
84
|
let(:analyze_multiplex) {
|
97
85
|
GraphQL::Analysis::AST.analyze_multiplex(multiplex, [GraphQL::Analysis::AST::MaxQueryComplexity])
|
98
86
|
}
|
@@ -2,14 +2,7 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe GraphQL::Analysis::AST::MaxQueryDepth do
|
5
|
-
|
6
|
-
@prev_max_depth = Dummy::Schema.max_depth
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
Dummy::Schema.max_depth = @prev_max_depth
|
11
|
-
end
|
12
|
-
|
5
|
+
let(:schema) { Class.new(Dummy::Schema) }
|
13
6
|
let(:query_string) { "
|
14
7
|
{
|
15
8
|
cheese(id: 1) {
|
@@ -30,7 +23,7 @@ describe GraphQL::Analysis::AST::MaxQueryDepth do
|
|
30
23
|
let(:max_depth) { nil }
|
31
24
|
let(:query) {
|
32
25
|
GraphQL::Query.new(
|
33
|
-
|
26
|
+
schema.graphql_definition,
|
34
27
|
query_string,
|
35
28
|
variables: {},
|
36
29
|
max_depth: max_depth
|
@@ -58,7 +51,7 @@ describe GraphQL::Analysis::AST::MaxQueryDepth do
|
|
58
51
|
|
59
52
|
describe "When the query is not deeper than max_depth" do
|
60
53
|
before do
|
61
|
-
|
54
|
+
schema.max_depth = 100
|
62
55
|
end
|
63
56
|
|
64
57
|
it "doesn't add an error" do
|
@@ -68,7 +61,7 @@ describe GraphQL::Analysis::AST::MaxQueryDepth do
|
|
68
61
|
|
69
62
|
describe "when the max depth isn't set" do
|
70
63
|
before do
|
71
|
-
|
64
|
+
schema.max_depth = nil
|
72
65
|
end
|
73
66
|
|
74
67
|
it "doesn't add an error message" do
|
@@ -78,7 +71,7 @@ describe GraphQL::Analysis::AST::MaxQueryDepth do
|
|
78
71
|
|
79
72
|
describe "when a fragment exceeds max depth" do
|
80
73
|
before do
|
81
|
-
|
74
|
+
schema.max_depth = 4
|
82
75
|
end
|
83
76
|
|
84
77
|
let(:query_string) { "
|
@@ -2,16 +2,8 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe GraphQL::Analysis::MaxQueryComplexity do
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
Dummy::Schema.max_complexity = @prev_max_complexity
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
let(:result) { Dummy::Schema.execute(query_string) }
|
5
|
+
let(:schema) { Class.new(Dummy::Schema) }
|
6
|
+
let(:result) { schema.execute(query_string) }
|
15
7
|
let(:query_string) {%|
|
16
8
|
{
|
17
9
|
a: cheese(id: 1) { id }
|
@@ -24,7 +16,7 @@ describe GraphQL::Analysis::MaxQueryComplexity do
|
|
24
16
|
|
25
17
|
describe "when a query goes over max complexity" do
|
26
18
|
before do
|
27
|
-
|
19
|
+
schema.max_complexity = 9
|
28
20
|
end
|
29
21
|
|
30
22
|
it "returns an error" do
|
@@ -34,7 +26,7 @@ describe GraphQL::Analysis::MaxQueryComplexity do
|
|
34
26
|
|
35
27
|
describe "when there is no max complexity" do
|
36
28
|
before do
|
37
|
-
|
29
|
+
schema.max_complexity = nil
|
38
30
|
end
|
39
31
|
it "doesn't error" do
|
40
32
|
assert_nil result["errors"]
|
@@ -43,7 +35,7 @@ describe GraphQL::Analysis::MaxQueryComplexity do
|
|
43
35
|
|
44
36
|
describe "when the query is less than the max complexity" do
|
45
37
|
before do
|
46
|
-
|
38
|
+
schema.max_complexity = 99
|
47
39
|
end
|
48
40
|
it "doesn't error" do
|
49
41
|
assert_nil result["errors"]
|
@@ -52,9 +44,9 @@ describe GraphQL::Analysis::MaxQueryComplexity do
|
|
52
44
|
|
53
45
|
describe "when max_complexity is decreased at query-level" do
|
54
46
|
before do
|
55
|
-
|
47
|
+
schema.max_complexity = 100
|
56
48
|
end
|
57
|
-
let(:result) {
|
49
|
+
let(:result) {schema.execute(query_string, max_complexity: 7) }
|
58
50
|
|
59
51
|
it "is applied" do
|
60
52
|
assert_equal "Query has complexity of 10, which exceeds max complexity of 7", result["errors"][0]["message"]
|
@@ -63,9 +55,9 @@ describe GraphQL::Analysis::MaxQueryComplexity do
|
|
63
55
|
|
64
56
|
describe "when max_complexity is increased at query-level" do
|
65
57
|
before do
|
66
|
-
|
58
|
+
schema.max_complexity = 1
|
67
59
|
end
|
68
|
-
let(:result) {
|
60
|
+
let(:result) {schema.execute(query_string, max_complexity: 10) }
|
69
61
|
|
70
62
|
it "doesn't error" do
|
71
63
|
assert_nil result["errors"]
|
@@ -74,13 +66,13 @@ describe GraphQL::Analysis::MaxQueryComplexity do
|
|
74
66
|
|
75
67
|
describe "across a multiplex" do
|
76
68
|
before do
|
77
|
-
|
69
|
+
schema.max_complexity = 9
|
78
70
|
end
|
79
71
|
|
80
72
|
let(:queries) { 5.times.map { |n| { query: "{ cheese(id: #{n}) { id } }" } } }
|
81
73
|
|
82
74
|
it "returns errors for all queries" do
|
83
|
-
results =
|
75
|
+
results = schema.multiplex(queries)
|
84
76
|
assert_equal 5, results.length
|
85
77
|
err_msg = "Query has complexity of 10, which exceeds max complexity of 9"
|
86
78
|
results.each do |res|
|
@@ -90,7 +82,7 @@ describe GraphQL::Analysis::MaxQueryComplexity do
|
|
90
82
|
|
91
83
|
describe "with a local override" do
|
92
84
|
it "uses the override" do
|
93
|
-
results =
|
85
|
+
results = schema.multiplex(queries, max_complexity: 10)
|
94
86
|
assert_equal 5, results.length
|
95
87
|
results.each do |res|
|
96
88
|
assert_equal true, res.key?("data")
|
@@ -2,15 +2,8 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe GraphQL::Analysis::MaxQueryDepth do
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
Dummy::Schema.max_depth = @prev_max_depth
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:result) { Dummy::Schema.execute(query_string) }
|
5
|
+
let(:schema) { Class.new(Dummy::Schema) }
|
6
|
+
let(:result) { schema.execute(query_string) }
|
14
7
|
let(:query_string) { "
|
15
8
|
{
|
16
9
|
cheese(id: 1) {
|
@@ -36,7 +29,7 @@ describe GraphQL::Analysis::MaxQueryDepth do
|
|
36
29
|
end
|
37
30
|
|
38
31
|
describe "when the query specifies a different max_depth" do
|
39
|
-
let(:result) {
|
32
|
+
let(:result) { schema.execute(query_string, max_depth: 100) }
|
40
33
|
|
41
34
|
it "obeys that max_depth" do
|
42
35
|
assert_nil result["errors"]
|
@@ -45,7 +38,7 @@ describe GraphQL::Analysis::MaxQueryDepth do
|
|
45
38
|
|
46
39
|
describe "When the query is not deeper than max_depth" do
|
47
40
|
before do
|
48
|
-
|
41
|
+
schema.max_depth = 100
|
49
42
|
end
|
50
43
|
|
51
44
|
it "doesn't add an error" do
|
@@ -55,7 +48,7 @@ describe GraphQL::Analysis::MaxQueryDepth do
|
|
55
48
|
|
56
49
|
describe "when the max depth isn't set" do
|
57
50
|
before do
|
58
|
-
|
51
|
+
schema.max_depth = nil
|
59
52
|
end
|
60
53
|
|
61
54
|
it "doesn't add an error message" do
|
@@ -65,7 +58,7 @@ describe GraphQL::Analysis::MaxQueryDepth do
|
|
65
58
|
|
66
59
|
describe "when a fragment exceeds max depth" do
|
67
60
|
before do
|
68
|
-
|
61
|
+
schema.max_depth = 4
|
69
62
|
end
|
70
63
|
|
71
64
|
let(:query_string) { "
|
@@ -53,6 +53,13 @@ describe GraphQL::Language::Lexer do
|
|
53
53
|
tokens = subject.tokenize('"""{"foo":"bar"}"""')
|
54
54
|
assert_equal '{"foo":"bar"}', tokens[0].value
|
55
55
|
end
|
56
|
+
|
57
|
+
it "tokenizes empty block strings correctly" do
|
58
|
+
empty_block_string = '""""""'
|
59
|
+
tokens = subject.tokenize(empty_block_string)
|
60
|
+
|
61
|
+
assert_equal '', tokens[0].value
|
62
|
+
end
|
56
63
|
end
|
57
64
|
|
58
65
|
it "unescapes escaped characters" do
|
@@ -67,6 +74,17 @@ describe GraphQL::Language::Lexer do
|
|
67
74
|
assert_equal :BAD_UNICODE_ESCAPE, subject.tokenize('"\\u0XXF \\u0009"').first.name
|
68
75
|
end
|
69
76
|
|
77
|
+
it "rejects truly invalid UTF-8 bytes" do
|
78
|
+
error_filename = "spec/support/parser/filename_example_invalid_utf8.graphql"
|
79
|
+
assert_equal :BAD_UNICODE_ESCAPE, subject.tokenize(File.read(error_filename)).first.name
|
80
|
+
end
|
81
|
+
|
82
|
+
it "rejects unicode that's well-formed but results in invalidly-encoded strings" do
|
83
|
+
# when the string here gets tokenized into an actual `:STRING`, it results in `valid_encoding?` being false for
|
84
|
+
# the ruby string so application code usually blows up trying to manipulate it
|
85
|
+
assert_equal :BAD_UNICODE_ESCAPE, subject.tokenize('"\\ud83c\\udf2c"').first.name
|
86
|
+
end
|
87
|
+
|
70
88
|
it "clears the previous_token between runs" do
|
71
89
|
tok_2 = subject.tokenize(query_string)
|
72
90
|
assert_nil tok_2[0].prev_token
|
@@ -80,7 +98,7 @@ describe GraphQL::Language::Lexer do
|
|
80
98
|
assert_equal 8, str_token.col
|
81
99
|
assert_equal '(STRING "c" [1:8])', str_token.inspect
|
82
100
|
rparen_token = tokens[6]
|
83
|
-
assert_equal '(RPAREN ")" [1:
|
101
|
+
assert_equal '(RPAREN ")" [1:11])', rparen_token.inspect
|
84
102
|
end
|
85
103
|
|
86
104
|
it "counts block string line properly" do
|
@@ -1063,6 +1063,16 @@ SCHEMA
|
|
1063
1063
|
|
1064
1064
|
assert_equal({ "str" => "abc", "int" => 123 }, result["data"])
|
1065
1065
|
end
|
1066
|
+
|
1067
|
+
it "doesn't warn about method conflicts" do
|
1068
|
+
assert_output "", "" do
|
1069
|
+
GraphQL::Schema.from_definition "
|
1070
|
+
type Query {
|
1071
|
+
int(method: Int): Int
|
1072
|
+
}
|
1073
|
+
"
|
1074
|
+
end
|
1075
|
+
end
|
1066
1076
|
end
|
1067
1077
|
|
1068
1078
|
describe "executable schemas from string" do
|
@@ -2,16 +2,13 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe GraphQL::Schema::CatchallMiddleware do
|
5
|
-
let(:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
Dummy::Schema.middleware << GraphQL::Schema::CatchallMiddleware
|
10
|
-
end
|
11
|
-
|
12
|
-
after do
|
13
|
-
Dummy::Schema.middleware.delete(GraphQL::Schema::CatchallMiddleware)
|
5
|
+
let(:schema) do
|
6
|
+
Class.new(Dummy::Schema) do
|
7
|
+
middleware GraphQL::Schema::CatchallMiddleware
|
8
|
+
end
|
14
9
|
end
|
10
|
+
let(:result) { schema.execute(query_string) }
|
11
|
+
let(:query_string) {%| query noMilk { error }|}
|
15
12
|
|
16
13
|
if TESTING_RESCUE_FROM
|
17
14
|
describe "rescuing errors" do
|
@@ -393,4 +393,29 @@ describe GraphQL::Schema::InputObject do
|
|
393
393
|
assert_equal ["ensembleId", "stringValue", "nestedInput", "legacyInput"], input_type["inputFields"].map { |f| f["name"] }
|
394
394
|
end
|
395
395
|
end
|
396
|
+
|
397
|
+
describe "warning for method objects" do
|
398
|
+
it "warns for method conflicts" do
|
399
|
+
input_object = Class.new(GraphQL::Schema::InputObject) do
|
400
|
+
graphql_name "X"
|
401
|
+
argument :method, String, required: true
|
402
|
+
end
|
403
|
+
|
404
|
+
expected_warning = "Unable to define a helper for argument with name 'method' as this is a reserved name. Add `method_access: false` to stop this warning.\n"
|
405
|
+
assert_output "", expected_warning do
|
406
|
+
input_object.graphql_definition
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
it "doesn't warn with `method_access: false`" do
|
411
|
+
input_object = Class.new(GraphQL::Schema::InputObject) do
|
412
|
+
graphql_name "X"
|
413
|
+
argument :method, String, required: true, method_access: false
|
414
|
+
end
|
415
|
+
|
416
|
+
assert_output "", "" do
|
417
|
+
input_object.graphql_definition
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end
|
396
421
|
end
|
@@ -275,7 +275,71 @@ describe GraphQL::Schema::Loader do
|
|
275
275
|
assert type.arguments['sub'].default_value.nil?
|
276
276
|
end
|
277
277
|
|
278
|
-
it "
|
278
|
+
it "doesnt warn about method conflicts (because it doesn't make method accesses)" do
|
279
|
+
assert_output "", "" do
|
280
|
+
GraphQL::Schema.from_introspection({
|
281
|
+
"data" => {
|
282
|
+
"__schema" => {
|
283
|
+
"queryType" => {
|
284
|
+
"name" => "Query"
|
285
|
+
},
|
286
|
+
"mutationType" => nil,
|
287
|
+
"subscriptionType" => nil,
|
288
|
+
"types" => [
|
289
|
+
{
|
290
|
+
"kind" => "OBJECT",
|
291
|
+
"name" => "Query",
|
292
|
+
"description" => nil,
|
293
|
+
"fields" => [
|
294
|
+
{
|
295
|
+
"name" => "int",
|
296
|
+
"description" => nil,
|
297
|
+
"args" => [
|
298
|
+
{
|
299
|
+
"name" => "method",
|
300
|
+
"description" => nil,
|
301
|
+
"type" => {
|
302
|
+
"kind" => "SCALAR",
|
303
|
+
"name" => "Int",
|
304
|
+
"ofType" => nil
|
305
|
+
},
|
306
|
+
"defaultValue" => nil
|
307
|
+
}
|
308
|
+
],
|
309
|
+
"type" => {
|
310
|
+
"kind" => "SCALAR",
|
311
|
+
"name" => "Int",
|
312
|
+
"ofType" => nil
|
313
|
+
},
|
314
|
+
"isDeprecated" => false,
|
315
|
+
"deprecationReason" => nil
|
316
|
+
}
|
317
|
+
],
|
318
|
+
"inputFields" => nil,
|
319
|
+
"interfaces" => [
|
320
|
+
|
321
|
+
],
|
322
|
+
"enumValues" => nil,
|
323
|
+
"possibleTypes" => nil
|
324
|
+
},
|
325
|
+
{
|
326
|
+
"kind" => "SCALAR",
|
327
|
+
"name" => "Int",
|
328
|
+
"description" => "Represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.",
|
329
|
+
"fields" => nil,
|
330
|
+
"inputFields" => nil,
|
331
|
+
"interfaces" => nil,
|
332
|
+
"enumValues" => nil,
|
333
|
+
"possibleTypes" => nil
|
334
|
+
},
|
335
|
+
]
|
336
|
+
}
|
337
|
+
}
|
338
|
+
})
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
it "sets correct default values `nil` on complex field arguments" do
|
279
343
|
type = loaded_schema.types['Query']
|
280
344
|
field = type.fields['post']
|
281
345
|
arg = field.arguments['variedWithNull']
|