graphql 0.11.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql.rb +5 -2
- data/lib/graphql/argument.rb +8 -3
- data/lib/graphql/base_type.rb +5 -3
- data/lib/graphql/boolean_type.rb +6 -1
- data/lib/graphql/define.rb +8 -0
- data/lib/graphql/define/assign_argument.rb +19 -0
- data/lib/graphql/define/assign_enum_value.rb +16 -0
- data/lib/graphql/define/assign_object_field.rb +19 -0
- data/lib/graphql/define/assignment_dictionary.rb +26 -0
- data/lib/graphql/define/defined_object_proxy.rb +32 -0
- data/lib/graphql/define/instance_definable.rb +79 -0
- data/lib/graphql/{definition_helpers → define}/non_null_with_bang.rb +1 -1
- data/lib/graphql/{definition_helpers → define}/type_definer.rb +1 -1
- data/lib/graphql/directive.rb +7 -2
- data/lib/graphql/enum_type.rb +12 -6
- data/lib/graphql/execution_error.rb +1 -1
- data/lib/graphql/field.rb +26 -23
- data/lib/graphql/float_type.rb +2 -3
- data/lib/graphql/id_type.rb +9 -1
- data/lib/graphql/input_object_type.rb +11 -8
- data/lib/graphql/int_type.rb +2 -1
- data/lib/graphql/interface_type.rb +7 -2
- data/lib/graphql/introspection/input_value_type.rb +10 -1
- data/lib/graphql/invalid_null_error.rb +1 -1
- data/lib/graphql/object_type.rb +27 -25
- data/lib/graphql/query.rb +5 -8
- data/lib/graphql/query/serial_execution/field_resolution.rb +0 -10
- data/lib/graphql/scalar_type.rb +4 -3
- data/lib/graphql/schema.rb +1 -1
- data/lib/graphql/static_validation/rules/document_does_not_exceed_max_depth.rb +1 -1
- data/lib/graphql/static_validation/validation_context.rb +5 -4
- data/lib/graphql/static_validation/validator.rb +3 -3
- data/lib/graphql/string_type.rb +2 -1
- data/lib/graphql/union_type.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/readme.md +4 -10
- data/spec/graphql/boolean_type_spec.rb +20 -0
- data/spec/graphql/define/instance_definable_spec.rb +55 -0
- data/spec/graphql/field_spec.rb +14 -2
- data/spec/graphql/float_type_spec.rb +15 -0
- data/spec/graphql/id_type_spec.rb +9 -0
- data/spec/graphql/int_type_spec.rb +15 -0
- data/spec/graphql/introspection/input_value_type_spec.rb +36 -0
- data/spec/graphql/introspection/type_type_spec.rb +0 -23
- data/spec/graphql/query_spec.rb +16 -0
- data/spec/graphql/static_validation/complexity_validator_spec.rb +1 -1
- data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/document_does_not_exceed_max_depth_spec.rb +9 -1
- data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +3 -2
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +5 -4
- data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +4 -3
- data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +4 -3
- data/spec/graphql/static_validation/type_stack_spec.rb +3 -2
- data/spec/graphql/static_validation/validator_spec.rb +3 -25
- data/spec/graphql/string_type_spec.rb +15 -0
- data/spec/support/dairy_app.rb +2 -0
- metadata +25 -9
- data/lib/graphql/definition_helpers.rb +0 -4
- data/lib/graphql/definition_helpers/defined_by_config.rb +0 -123
- data/lib/graphql/definition_helpers/string_named_hash.rb +0 -22
data/spec/graphql/field_spec.rb
CHANGED
@@ -21,6 +21,7 @@ describe GraphQL::Field do
|
|
21
21
|
describe '.property ' do
|
22
22
|
let(:field) do
|
23
23
|
GraphQL::Field.define do
|
24
|
+
name 'field_name'
|
24
25
|
# satisfies 'can define by config' below
|
25
26
|
property :internal_prop
|
26
27
|
end
|
@@ -37,7 +38,7 @@ describe GraphQL::Field do
|
|
37
38
|
|
38
39
|
describe 'default resolver' do
|
39
40
|
def acts_like_default_resolver(field, old_prop, new_prop)
|
40
|
-
object = OpenStruct.new(old_prop => 'old value', new_prop => 'new value')
|
41
|
+
object = OpenStruct.new(old_prop => 'old value', new_prop => 'new value', field.name.to_sym => 'unset value')
|
41
42
|
|
42
43
|
old_result = field.resolve(object, nil, nil)
|
43
44
|
field.property = new_prop
|
@@ -47,7 +48,7 @@ describe GraphQL::Field do
|
|
47
48
|
|
48
49
|
assert_equal(old_result, 'old value')
|
49
50
|
assert_equal(new_result, 'new value')
|
50
|
-
assert_equal(unset_result,
|
51
|
+
assert_equal(unset_result, 'unset value')
|
51
52
|
end
|
52
53
|
|
53
54
|
it 'responds to changes in property' do
|
@@ -60,4 +61,15 @@ describe GraphQL::Field do
|
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
64
|
+
|
65
|
+
describe "#name" do
|
66
|
+
it "can't be reassigned" do
|
67
|
+
field = GraphQL::Field.define do
|
68
|
+
name("something")
|
69
|
+
end
|
70
|
+
assert_equal "something", field.name
|
71
|
+
assert_raises { field.name = "somethingelse" }
|
72
|
+
assert_equal "something", field.name
|
73
|
+
end
|
74
|
+
end
|
63
75
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GraphQL::FLOAT_TYPE do
|
4
|
+
describe "coerce_input" do
|
5
|
+
it "accepts ints and floats" do
|
6
|
+
assert_equal 1.0, GraphQL::FLOAT_TYPE.coerce_input(1)
|
7
|
+
assert_equal 6.1, GraphQL::FLOAT_TYPE.coerce_input(6.1)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "rejects other types" do
|
11
|
+
assert_equal nil, GraphQL::FLOAT_TYPE.coerce_input("55")
|
12
|
+
assert_equal nil, GraphQL::FLOAT_TYPE.coerce_input(true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -20,4 +20,13 @@ describe GraphQL::ID_TYPE do
|
|
20
20
|
assert_equal(expected, result)
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
describe 'coercion for other types' do
|
25
|
+
let(:query_string) { %|query getMilk { cow: milk(id: 1.0) { id } }| }
|
26
|
+
|
27
|
+
it "doesn't allow other types" do
|
28
|
+
assert_equal nil, result["data"]
|
29
|
+
assert_equal 1, result["errors"].length
|
30
|
+
end
|
31
|
+
end
|
23
32
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GraphQL::INT_TYPE do
|
4
|
+
describe "coerce_input" do
|
5
|
+
it "accepts ints and floats" do
|
6
|
+
assert_equal 1, GraphQL::INT_TYPE.coerce_input(1)
|
7
|
+
assert_equal 6, GraphQL::INT_TYPE.coerce_input(6.1)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "rejects other types" do
|
11
|
+
assert_equal nil, GraphQL::INT_TYPE.coerce_input("55")
|
12
|
+
assert_equal nil, GraphQL::INT_TYPE.coerce_input(true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
|
4
|
+
describe GraphQL::Introspection::InputValueType do
|
5
|
+
let(:query_string) {%|
|
6
|
+
{
|
7
|
+
__type(name: "DairyProductInput") {
|
8
|
+
name,
|
9
|
+
description,
|
10
|
+
kind,
|
11
|
+
inputFields {
|
12
|
+
name,
|
13
|
+
type { name },
|
14
|
+
defaultValue
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|}
|
19
|
+
let(:result) { DummySchema.execute(query_string)}
|
20
|
+
|
21
|
+
it 'exposes metadata about input objects, giving extra quotes for strings' do
|
22
|
+
expected = { "data" => {
|
23
|
+
"__type" => {
|
24
|
+
"name"=>"DairyProductInput",
|
25
|
+
"description"=>"Properties for finding a dairy product",
|
26
|
+
"kind"=>"INPUT_OBJECT",
|
27
|
+
"inputFields"=>[
|
28
|
+
{"name"=>"source", "type"=>{ "name" => "Non-Null"}, "defaultValue"=>nil},
|
29
|
+
{"name"=>"originDairy", "type"=>{ "name" => "String"}, "defaultValue"=>"\"Sugar Hollow Dairy\""},
|
30
|
+
{"name"=>"fatContent", "type"=>{ "name" => "Float"}, "defaultValue"=>nil}
|
31
|
+
]
|
32
|
+
}
|
33
|
+
}}
|
34
|
+
assert_equal(expected, result)
|
35
|
+
end
|
36
|
+
end
|
@@ -90,28 +90,5 @@ describe GraphQL::Introspection::TypeType do
|
|
90
90
|
}}
|
91
91
|
assert_equal(expected, result)
|
92
92
|
end
|
93
|
-
|
94
|
-
describe 'input objects' do
|
95
|
-
let(:query_string) {%|
|
96
|
-
query introspectionQuery {
|
97
|
-
__type(name: "DairyProductInput") { name, description, kind, inputFields { name, type { name }, defaultValue } }
|
98
|
-
}
|
99
|
-
|}
|
100
|
-
|
101
|
-
it 'exposes metadata about input objects' do
|
102
|
-
expected = { "data" => {
|
103
|
-
"__type" => {
|
104
|
-
"name"=>"DairyProductInput",
|
105
|
-
"description"=>"Properties for finding a dairy product",
|
106
|
-
"kind"=>"INPUT_OBJECT",
|
107
|
-
"inputFields"=>[
|
108
|
-
{"name"=>"source", "type"=>{ "name" => "Non-Null"}, "defaultValue"=>nil},
|
109
|
-
{"name"=>"fatContent", "type"=>{ "name" => "Float"}, "defaultValue"=>nil}
|
110
|
-
]
|
111
|
-
}
|
112
|
-
}}
|
113
|
-
assert_equal(expected, result)
|
114
|
-
end
|
115
|
-
end
|
116
93
|
end
|
117
94
|
end
|
data/spec/graphql/query_spec.rb
CHANGED
@@ -30,6 +30,7 @@ describe GraphQL::Query do
|
|
30
30
|
|}
|
31
31
|
let(:debug) { false }
|
32
32
|
let(:operation_name) { nil }
|
33
|
+
let(:max_depth) { nil }
|
33
34
|
let(:query_variables) { {"cheeseId" => 2} }
|
34
35
|
let(:schema) { DummySchema }
|
35
36
|
let(:query) { GraphQL::Query.new(
|
@@ -38,6 +39,7 @@ describe GraphQL::Query do
|
|
38
39
|
variables: query_variables,
|
39
40
|
debug: debug,
|
40
41
|
operation_name: operation_name,
|
42
|
+
max_depth: max_depth,
|
41
43
|
)}
|
42
44
|
let(:result) { query.result }
|
43
45
|
describe '#result' do
|
@@ -317,4 +319,18 @@ describe GraphQL::Query do
|
|
317
319
|
end
|
318
320
|
end
|
319
321
|
end
|
322
|
+
|
323
|
+
describe "#max_depth" do
|
324
|
+
it "defaults to the schema's max_depth" do
|
325
|
+
assert_equal 5, query.max_depth
|
326
|
+
end
|
327
|
+
|
328
|
+
describe "overriding max_depth" do
|
329
|
+
let(:max_depth) { 12 }
|
330
|
+
|
331
|
+
it "overrides the schema's max_depth" do
|
332
|
+
assert_equal 12, query.max_depth
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
320
336
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# require "spec_helper"
|
2
2
|
#
|
3
3
|
# describe GraphQL::StaticValidation::ComplexityValidator do
|
4
|
-
# let(:
|
4
|
+
# let(:query_string) {query_string)}
|
5
5
|
# let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [complexity_validator]) }
|
6
6
|
# let(:errors) { validator.validate(document) }
|
7
7
|
# let(:complexity_validator) { GraphQL::StaticValidation::ComplexityValidator.new(max_fields: 6, list_multiplier: 2) }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GraphQL::StaticValidation::ArgumentLiteralsAreCompatible do
|
4
|
-
let(:
|
4
|
+
let(:query_string) {%|
|
5
5
|
query getCheese {
|
6
6
|
cheese(id: "aasdlkfj") { source }
|
7
7
|
cheese(id: 1) { source @skip(if: {id: 1})}
|
@@ -15,10 +15,11 @@ describe GraphQL::StaticValidation::ArgumentLiteralsAreCompatible do
|
|
15
15
|
fragment cheeseFields on Cheese {
|
16
16
|
similarCheese(source: 4.5)
|
17
17
|
}
|
18
|
-
|
|
18
|
+
|}
|
19
19
|
|
20
20
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::ArgumentLiteralsAreCompatible]) }
|
21
|
-
let(:
|
21
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
22
|
+
let(:errors) { validator.validate(query) }
|
22
23
|
|
23
24
|
it 'finds undefined or missing-required arguments to fields and directives' do
|
24
25
|
assert_equal(6, errors.length)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GraphQL::StaticValidation::ArgumentsAreDefined do
|
4
|
-
let(:
|
4
|
+
let(:query_string) {"
|
5
5
|
query getCheese {
|
6
6
|
cheese(id: 1) { source }
|
7
7
|
cheese(silly: false) { source }
|
@@ -12,10 +12,11 @@ describe GraphQL::StaticValidation::ArgumentsAreDefined do
|
|
12
12
|
similarCheese(source: SHEEP, nonsense: 1)
|
13
13
|
id @skip(something: 3.4)
|
14
14
|
}
|
15
|
-
"
|
15
|
+
"}
|
16
16
|
|
17
17
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::ArgumentsAreDefined]) }
|
18
|
-
let(:
|
18
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
19
|
+
let(:errors) { validator.validate(query) }
|
19
20
|
|
20
21
|
it 'finds undefined arguments to fields and directives' do
|
21
22
|
assert_equal(4, errors.length)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GraphQL::StaticValidation::DirectivesAreDefined do
|
4
|
-
let(:
|
4
|
+
let(:query_string) {"
|
5
5
|
query getCheese {
|
6
6
|
okCheese: cheese(id: 1) {
|
7
7
|
id @skip(if: true),
|
@@ -11,10 +11,11 @@ describe GraphQL::StaticValidation::DirectivesAreDefined do
|
|
11
11
|
}
|
12
12
|
}
|
13
13
|
}
|
14
|
-
"
|
14
|
+
"}
|
15
15
|
|
16
16
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::DirectivesAreDefined]) }
|
17
|
-
let(:
|
17
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
18
|
+
let(:errors) { validator.validate(query) }
|
18
19
|
|
19
20
|
describe 'non-existent directives' do
|
20
21
|
it 'makes errors for them' do
|
@@ -3,7 +3,8 @@ require "spec_helper"
|
|
3
3
|
describe GraphQL::StaticValidation::DocumentDoesNotExceedMaxDepth do
|
4
4
|
let(:rule) { GraphQL::StaticValidation::DocumentDoesNotExceedMaxDepth }
|
5
5
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [rule]) }
|
6
|
-
let(:
|
6
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
7
|
+
let(:errors) { validator.validate(query) }
|
7
8
|
|
8
9
|
let(:query_string) { "
|
9
10
|
{
|
@@ -29,6 +30,13 @@ describe GraphQL::StaticValidation::DocumentDoesNotExceedMaxDepth do
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
33
|
+
describe "when the query specifies a different max_depth" do
|
34
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string, max_depth: 100) }
|
35
|
+
it "obeys that max_depth" do
|
36
|
+
assert_equal 0, errors.length
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
32
40
|
describe "When the query is not deeper than max_depth" do
|
33
41
|
before do
|
34
42
|
@prev_max_depth = DummySchema.max_depth
|
@@ -12,8 +12,9 @@ describe GraphQL::StaticValidation::FieldsAreDefinedOnType do
|
|
12
12
|
"}
|
13
13
|
|
14
14
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::FieldsAreDefinedOnType]) }
|
15
|
-
let(:
|
16
|
-
let(:
|
15
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
16
|
+
let(:errors) { validator.validate(query) }
|
17
|
+
let(:error_messages) { errors.map { |e| e["message"] } }
|
17
18
|
|
18
19
|
it "finds fields that are requested on types that don't have that field" do
|
19
20
|
expected_errors = [
|
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GraphQL::StaticValidation::FieldsHaveAppropriateSelections do
|
4
|
-
let(:
|
4
|
+
let(:query_string) {"
|
5
5
|
query getCheese {
|
6
6
|
okCheese: cheese(id: 1) { fatContent, similarCheese(source: YAK) { source } }
|
7
7
|
missingFieldsCheese: cheese(id: 1)
|
8
8
|
illegalSelectionCheese: cheese(id: 1) { id { something, ... someFields } }
|
9
9
|
}
|
10
|
-
"
|
10
|
+
"}
|
11
11
|
|
12
12
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::FieldsHaveAppropriateSelections]) }
|
13
|
-
let(:
|
13
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
14
|
+
let(:errors) { validator.validate(query) }
|
14
15
|
|
15
16
|
it 'adds errors for selections on scalars' do
|
16
17
|
assert_equal(2, errors.length)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GraphQL::StaticValidation::FieldsWillMerge do
|
4
|
-
let(:
|
4
|
+
let(:query_string) {"
|
5
5
|
query getCheese($sourceVar: DairyAnimal!) {
|
6
6
|
cheese(id: 1) {
|
7
7
|
id,
|
@@ -27,10 +27,11 @@ describe GraphQL::StaticValidation::FieldsWillMerge do
|
|
27
27
|
similarCow: similarCheese(source: COW) { similarCowSource: id, id }
|
28
28
|
id @someFlag
|
29
29
|
}
|
30
|
-
"
|
30
|
+
"}
|
31
31
|
|
32
32
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::FieldsWillMerge]) }
|
33
|
-
let(:
|
33
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
34
|
+
let(:errors) { validator.validate(query) }
|
34
35
|
let(:error_messages) { errors.map { |e| e["message" ] }}
|
35
36
|
|
36
37
|
it 'finds field naming conflicts' do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GraphQL::StaticValidation::FragmentSpreadsArePossible do
|
4
|
-
let(:
|
4
|
+
let(:query_string) {%|
|
5
5
|
query getCheese {
|
6
6
|
cheese(id: 1) {
|
7
7
|
... milkFields
|
@@ -20,10 +20,11 @@ describe GraphQL::StaticValidation::FragmentSpreadsArePossible do
|
|
20
20
|
fatContent
|
21
21
|
... milkFields
|
22
22
|
}
|
23
|
-
|
|
23
|
+
|}
|
24
24
|
|
25
25
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::FragmentSpreadsArePossible]) }
|
26
|
-
let(:
|
26
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
27
|
+
let(:errors) { validator.validate(query) }
|
27
28
|
|
28
29
|
it "doesnt allow spreads where they'll never apply" do
|
29
30
|
# TODO: more negative, abstract examples here, add stuff to the schema
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GraphQL::StaticValidation::FragmentTypesExist do
|
4
|
-
let(:
|
4
|
+
let(:query_string) {"
|
5
5
|
query getCheese {
|
6
6
|
cheeese(id: 1) {
|
7
7
|
... on Cheese { source }
|
@@ -17,10 +17,11 @@ describe GraphQL::StaticValidation::FragmentTypesExist do
|
|
17
17
|
fragment cheeseFields on Cheese {
|
18
18
|
fatContent
|
19
19
|
}
|
20
|
-
"
|
20
|
+
"}
|
21
21
|
|
22
22
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::FragmentTypesExist]) }
|
23
|
-
let(:
|
23
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
24
|
+
let(:errors) { validator.validate(query) }
|
24
25
|
|
25
26
|
it 'finds non-existent types on fragments' do
|
26
27
|
assert_equal(2, errors.length)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GraphQL::StaticValidation::FragmentsAreFinite do
|
4
|
-
let(:
|
4
|
+
let(:query_string) {%|
|
5
5
|
query getCheese {
|
6
6
|
cheese(id: 1) {
|
7
7
|
... idField
|
@@ -22,10 +22,11 @@ describe GraphQL::StaticValidation::FragmentsAreFinite do
|
|
22
22
|
fragment idField on Cheese {
|
23
23
|
id
|
24
24
|
}
|
25
|
-
|
|
25
|
+
|}
|
26
26
|
|
27
27
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::FragmentsAreFinite]) }
|
28
|
-
let(:
|
28
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
29
|
+
let(:errors) { validator.validate(query) }
|
29
30
|
|
30
31
|
it 'doesnt allow infinite loops' do
|
31
32
|
expected = [
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GraphQL::StaticValidation::FragmentsAreOnCompositeTypes do
|
4
|
-
let(:
|
4
|
+
let(:query_string) {%|
|
5
5
|
query getCheese {
|
6
6
|
cheese(id: 1) {
|
7
7
|
... on Cheese {
|
@@ -23,10 +23,11 @@ describe GraphQL::StaticValidation::FragmentsAreOnCompositeTypes do
|
|
23
23
|
fragment intFields on Int {
|
24
24
|
something
|
25
25
|
}
|
26
|
-
|
|
26
|
+
|}
|
27
27
|
|
28
28
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::FragmentsAreOnCompositeTypes]) }
|
29
|
-
let(:
|
29
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
30
|
+
let(:errors) { validator.validate(query) }
|
30
31
|
|
31
32
|
it 'requires Object/Union/Interface fragment types' do
|
32
33
|
expected = [
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GraphQL::StaticValidation::FragmentsAreUsed do
|
4
|
-
let(:
|
4
|
+
let(:query_string) {"
|
5
5
|
query getCheese {
|
6
6
|
name,
|
7
7
|
...cheeseFields
|
@@ -9,10 +9,11 @@ describe GraphQL::StaticValidation::FragmentsAreUsed do
|
|
9
9
|
}
|
10
10
|
fragment cheeseFields on Cheese { fatContent }
|
11
11
|
fragment unusedFields on Cheese { is, not, used }
|
12
|
-
"
|
12
|
+
"}
|
13
13
|
|
14
14
|
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::FragmentsAreUsed]) }
|
15
|
-
let(:
|
15
|
+
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
16
|
+
let(:errors) { validator.validate(query) }
|
16
17
|
|
17
18
|
it 'adds errors for unused fragment definitions' do
|
18
19
|
assert_includes(errors, {"message"=>"Fragment unusedFields was defined, but not used", "locations"=>[{"line"=>8, "column"=>5}]})
|