graphql 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/graphql/define/assign_argument.rb +3 -5
- data/lib/graphql/field.rb +1 -3
- data/lib/graphql/input_object_type.rb +4 -1
- data/lib/graphql/language.rb +1 -0
- data/lib/graphql/language/generation.rb +94 -0
- data/lib/graphql/language/lexer.rb +229 -201
- data/lib/graphql/language/lexer.rl +24 -7
- data/lib/graphql/language/nodes.rb +4 -0
- data/lib/graphql/language/parser.rb +195 -187
- data/lib/graphql/language/parser.y +11 -4
- data/lib/graphql/object_type.rb +21 -0
- data/lib/graphql/query.rb +8 -3
- data/lib/graphql/query/serial_execution/operation_resolution.rb +2 -2
- data/lib/graphql/query/serial_execution/value_resolution.rb +5 -0
- data/lib/graphql/schema.rb +11 -19
- data/lib/graphql/schema/invalid_type_error.rb +6 -0
- data/lib/graphql/schema/reduce_types.rb +68 -0
- data/lib/graphql/schema/type_expression.rb +6 -16
- data/lib/graphql/schema/type_map.rb +1 -5
- data/lib/graphql/schema/validation.rb +164 -0
- data/lib/graphql/version.rb +1 -1
- data/readme.md +3 -4
- data/spec/graphql/argument_spec.rb +20 -0
- data/spec/graphql/field_spec.rb +16 -0
- data/spec/graphql/introspection/schema_type_spec.rb +1 -0
- data/spec/graphql/language/generation_spec.rb +42 -0
- data/spec/graphql/language/parser_spec.rb +136 -26
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +23 -0
- data/spec/graphql/query_spec.rb +51 -0
- data/spec/graphql/schema/{type_reducer_spec.rb → reduce_types_spec.rb} +16 -14
- data/spec/graphql/schema/type_expression_spec.rb +4 -4
- data/spec/graphql/schema/validation_spec.rb +219 -0
- data/spec/support/dairy_app.rb +3 -0
- metadata +14 -13
- data/lib/graphql/schema/each_item_validator.rb +0 -21
- data/lib/graphql/schema/field_validator.rb +0 -17
- data/lib/graphql/schema/implementation_validator.rb +0 -31
- data/lib/graphql/schema/type_reducer.rb +0 -79
- data/lib/graphql/schema/type_validator.rb +0 -58
- data/spec/graphql/schema/field_validator_spec.rb +0 -21
- data/spec/graphql/schema/type_validator_spec.rb +0 -81
@@ -1,58 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
class Schema
|
3
|
-
class TypeValidator
|
4
|
-
def validate(type, errors)
|
5
|
-
own_errors = []
|
6
|
-
implementation = GraphQL::Schema::ImplementationValidator.new(type, as: "Type", errors: own_errors)
|
7
|
-
implementation.must_respond_to(:name)
|
8
|
-
implementation.must_respond_to(:kind)
|
9
|
-
if own_errors.any? # if no name or kind, abort!
|
10
|
-
errors.push(*own_errors)
|
11
|
-
return
|
12
|
-
end
|
13
|
-
|
14
|
-
type_name = type.name
|
15
|
-
kind_name = type.kind.name
|
16
|
-
|
17
|
-
implementation.must_respond_to(:description, as: kind_name)
|
18
|
-
each_item_validator = GraphQL::Schema::EachItemValidator.new(own_errors)
|
19
|
-
|
20
|
-
if type.kind.fields?
|
21
|
-
field_validator = GraphQL::Schema::FieldValidator.new
|
22
|
-
implementation.must_respond_to(:fields, as: kind_name) do |fields|
|
23
|
-
each_item_validator.validate(fields.keys, as: "#{type.name}.fields keys", must_be: "Strings") { |k| k.is_a?(String) }
|
24
|
-
|
25
|
-
fields.values.each do |field|
|
26
|
-
field_validator.validate(field, own_errors)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
if type.kind.union?
|
32
|
-
implementation.must_respond_to(:resolve_type)
|
33
|
-
implementation.must_respond_to(:possible_types, as: kind_name) do |possible_types|
|
34
|
-
each_item_validator.validate(possible_types, as: "#{type_name}.possible_types", must_be: "objects") { |t| t.kind.object? }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
if type.kind.object?
|
39
|
-
implementation.must_respond_to(:interfaces, as: kind_name) do |interfaces|
|
40
|
-
each_item_validator.validate(interfaces, as: "#{type_name}.interfaces", must_be: "interfaces") { |t| t.kind.interface? }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
if type.kind.input_object?
|
45
|
-
implementation.must_respond_to(:input_fields, as: kind_name)
|
46
|
-
end
|
47
|
-
|
48
|
-
if type.kind.union?
|
49
|
-
union_types = type.possible_types
|
50
|
-
if union_types.none?
|
51
|
-
own_errors << "Union #{type_name} must be defined with 1 or more types, not 0!"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
errors.push(*own_errors)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::Schema::FieldValidator do
|
4
|
-
let(:field_defn) {{
|
5
|
-
name: "Field",
|
6
|
-
description: "Invalid field",
|
7
|
-
deprecation_reason: nil,
|
8
|
-
arguments: {symbol_arg: nil},
|
9
|
-
type: DairyAnimalEnum,
|
10
|
-
}}
|
11
|
-
let(:field) {
|
12
|
-
f = OpenStruct.new(field_defn)
|
13
|
-
def f.to_s; f.name; end
|
14
|
-
f
|
15
|
-
}
|
16
|
-
let(:errors) { e = []; GraphQL::Schema::FieldValidator.new.validate(field, e); e }
|
17
|
-
it "requires argument names to be strings" do
|
18
|
-
expected = ["Field.arguments keys must be Strings, but some aren't: symbol_arg"]
|
19
|
-
assert_equal(expected, errors)
|
20
|
-
end
|
21
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::Schema::TypeValidator do
|
4
|
-
let(:base_type_defn) {
|
5
|
-
{
|
6
|
-
name: "InvalidType",
|
7
|
-
description: "...",
|
8
|
-
deprecation_reason: nil,
|
9
|
-
kind: GraphQL::TypeKinds::OBJECT,
|
10
|
-
interfaces: [],
|
11
|
-
fields: {},
|
12
|
-
}
|
13
|
-
}
|
14
|
-
let(:object) {
|
15
|
-
o = OpenStruct.new(type_defn)
|
16
|
-
def o.to_s; "InvalidType"; end
|
17
|
-
o
|
18
|
-
}
|
19
|
-
let(:validator) { GraphQL::Schema::TypeValidator.new }
|
20
|
-
let(:errors) { e = []; validator.validate(object, e); e;}
|
21
|
-
describe "when name isnt defined" do
|
22
|
-
let(:type_defn) { base_type_defn.delete_if {|k,v| k == :name }}
|
23
|
-
it "requires name" do
|
24
|
-
assert_equal(
|
25
|
-
["InvalidType must respond to #name() to be a Type"],
|
26
|
-
errors
|
27
|
-
)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "when a method returns nil" do
|
32
|
-
let(:type_defn) { base_type_defn.merge(interfaces: nil)}
|
33
|
-
it "requires name" do
|
34
|
-
assert_equal(
|
35
|
-
["InvalidType must return a value for #interfaces() to be a OBJECT"],
|
36
|
-
errors
|
37
|
-
)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "when a field name isnt a string" do
|
42
|
-
let(:type_defn) { base_type_defn.merge(fields: {symbol_field: (GraphQL::Field.new {|f|}) }) }
|
43
|
-
it "requires string names" do
|
44
|
-
assert_equal(
|
45
|
-
["InvalidType.fields keys must be Strings, but some aren't: symbol_field"],
|
46
|
-
errors
|
47
|
-
)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "when a Union isnt valid" do
|
52
|
-
let(:object) {
|
53
|
-
union_types = types
|
54
|
-
GraphQL::UnionType.define do
|
55
|
-
name "Something"
|
56
|
-
description "some union"
|
57
|
-
possible_types union_types
|
58
|
-
end
|
59
|
-
}
|
60
|
-
let(:errors) { e = []; GraphQL::Schema::TypeValidator.new.validate(object, e); e;}
|
61
|
-
|
62
|
-
describe "when non-object types" do
|
63
|
-
let(:types) { [DairyProductInputType] }
|
64
|
-
it "must be must be only object types" do
|
65
|
-
expected = [
|
66
|
-
"Something.possible_types must be objects, but some aren't: DairyProductInput"
|
67
|
-
]
|
68
|
-
assert_equal(expected, errors)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
describe "when no types" do
|
72
|
-
let(:types) { [] }
|
73
|
-
it "must have a type" do
|
74
|
-
expected = [
|
75
|
-
"Union Something must be defined with 1 or more types, not 0!"
|
76
|
-
]
|
77
|
-
assert_equal(expected, errors)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|