graphql 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/introspection/schema_type.rb +3 -3
- data/lib/graphql/language/nodes.rb +1 -1
- data/lib/graphql/query.rb +39 -27
- data/lib/graphql/query/executor.rb +1 -1
- data/lib/graphql/query/variables.rb +21 -28
- data/lib/graphql/relay/connection_type.rb +2 -0
- data/lib/graphql/relay/relation_connection.rb +8 -2
- data/lib/graphql/schema.rb +3 -0
- data/lib/graphql/schema/warden.rb +9 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/spec/graphql/analysis/analyze_query_spec.rb +15 -15
- data/spec/graphql/analysis/field_usage_spec.rb +1 -1
- data/spec/graphql/analysis/max_query_complexity_spec.rb +8 -8
- data/spec/graphql/analysis/max_query_depth_spec.rb +7 -7
- data/spec/graphql/analysis/query_complexity_spec.rb +2 -2
- data/spec/graphql/analysis/query_depth_spec.rb +1 -1
- data/spec/graphql/base_type_spec.rb +19 -11
- data/spec/graphql/directive_spec.rb +1 -1
- data/spec/graphql/enum_type_spec.rb +2 -2
- data/spec/graphql/execution/typecast_spec.rb +19 -19
- data/spec/graphql/execution_error_spec.rb +1 -1
- data/spec/graphql/field_spec.rb +15 -7
- data/spec/graphql/id_type_spec.rb +1 -1
- data/spec/graphql/input_object_type_spec.rb +16 -16
- data/spec/graphql/interface_type_spec.rb +6 -6
- data/spec/graphql/internal_representation/rewrite_spec.rb +34 -34
- data/spec/graphql/introspection/directive_type_spec.rb +1 -1
- data/spec/graphql/introspection/input_value_type_spec.rb +2 -2
- data/spec/graphql/introspection/introspection_query_spec.rb +1 -1
- data/spec/graphql/introspection/schema_type_spec.rb +2 -2
- data/spec/graphql/introspection/type_type_spec.rb +1 -1
- data/spec/graphql/language/parser_spec.rb +1 -1
- data/spec/graphql/non_null_type_spec.rb +3 -3
- data/spec/graphql/object_type_spec.rb +8 -8
- data/spec/graphql/query/executor_spec.rb +4 -4
- data/spec/graphql/query/variables_spec.rb +20 -4
- data/spec/graphql/query_spec.rb +20 -2
- data/spec/graphql/relay/connection_type_spec.rb +1 -1
- data/spec/graphql/relay/mutation_spec.rb +9 -9
- data/spec/graphql/relay/node_spec.rb +8 -8
- data/spec/graphql/relay/relation_connection_spec.rb +24 -6
- data/spec/graphql/schema/catchall_middleware_spec.rb +3 -3
- data/spec/graphql/schema/reduce_types_spec.rb +9 -9
- data/spec/graphql/schema/type_expression_spec.rb +3 -3
- data/spec/graphql/schema/validation_spec.rb +1 -1
- data/spec/graphql/schema/warden_spec.rb +79 -0
- data/spec/graphql/schema_spec.rb +2 -2
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +1 -1
- data/spec/graphql/static_validation/type_stack_spec.rb +2 -2
- data/spec/graphql/static_validation/validator_spec.rb +2 -2
- data/spec/graphql/union_type_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/dummy/data.rb +27 -0
- data/spec/support/dummy/schema.rb +369 -0
- data/spec/support/star_wars/data.rb +81 -0
- data/spec/support/star_wars/schema.rb +250 -0
- data/spec/support/static_validation_helpers.rb +2 -2
- metadata +10 -10
- data/spec/support/dairy_app.rb +0 -369
- data/spec/support/dairy_data.rb +0 -26
- data/spec/support/star_wars_data.rb +0 -80
- data/spec/support/star_wars_schema.rb +0 -242
@@ -2,8 +2,8 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe GraphQL::InternalRepresentation::Rewrite do
|
5
|
-
let(:validator) { GraphQL::StaticValidation::Validator.new(schema:
|
6
|
-
let(:query) { GraphQL::Query.new(
|
5
|
+
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: Dummy::Schema) }
|
6
|
+
let(:query) { GraphQL::Query.new(Dummy::Schema, query_string) }
|
7
7
|
let(:rewrite_result) {
|
8
8
|
validator.validate(query)[:irep]
|
9
9
|
}
|
@@ -24,18 +24,18 @@ describe GraphQL::InternalRepresentation::Rewrite do
|
|
24
24
|
it "produces a tree of nodes" do
|
25
25
|
op_node = rewrite_result["getCheeses"]
|
26
26
|
|
27
|
-
root_children = op_node.typed_children[DairyAppQueryType]
|
27
|
+
root_children = op_node.typed_children[Dummy::DairyAppQueryType]
|
28
28
|
assert_equal 2, root_children.length
|
29
|
-
assert_equal DairyAppQueryType, op_node.return_type
|
29
|
+
assert_equal Dummy::DairyAppQueryType, op_node.return_type
|
30
30
|
first_field = root_children.values.first
|
31
|
-
assert_equal 3, first_field.typed_children[CheeseType].length
|
32
|
-
assert_equal DairyAppQueryType, first_field.owner_type
|
33
|
-
assert_equal CheeseType, first_field.return_type
|
31
|
+
assert_equal 3, first_field.typed_children[Dummy::CheeseType].length
|
32
|
+
assert_equal Dummy::DairyAppQueryType, first_field.owner_type
|
33
|
+
assert_equal Dummy::CheeseType, first_field.return_type
|
34
34
|
|
35
35
|
second_field = root_children.values.last
|
36
|
-
assert_equal 1, second_field.typed_children[CheeseType].length
|
37
|
-
assert_equal DairyAppQueryType.get_field("cheese"), second_field.definition
|
38
|
-
assert_equal CheeseType, second_field.return_type
|
36
|
+
assert_equal 1, second_field.typed_children[Dummy::CheeseType].length
|
37
|
+
assert_equal Dummy::DairyAppQueryType.get_field("cheese"), second_field.definition
|
38
|
+
assert_equal Dummy::CheeseType, second_field.return_type
|
39
39
|
assert second_field.inspect.is_a?(String)
|
40
40
|
end
|
41
41
|
end
|
@@ -50,8 +50,8 @@ describe GraphQL::InternalRepresentation::Rewrite do
|
|
50
50
|
|}
|
51
51
|
|
52
52
|
it "gets dynamic field definitions" do
|
53
|
-
cheese_field = rewrite_result[nil].typed_children[DairyAppQueryType]["cheese"]
|
54
|
-
typename_field = cheese_field.typed_children[CheeseType]["typename"]
|
53
|
+
cheese_field = rewrite_result[nil].typed_children[Dummy::DairyAppQueryType]["cheese"]
|
54
|
+
typename_field = cheese_field.typed_children[Dummy::CheeseType]["typename"]
|
55
55
|
assert_equal "__typename", typename_field.definition.name
|
56
56
|
assert_equal "__typename", typename_field.definition_name
|
57
57
|
end
|
@@ -128,41 +128,41 @@ describe GraphQL::InternalRepresentation::Rewrite do
|
|
128
128
|
it "puts all fragment members as children" do
|
129
129
|
op_node = rewrite_result[nil]
|
130
130
|
|
131
|
-
cheese_field = op_node.typed_children[DairyAppQueryType]["cheese"]
|
132
|
-
assert_equal ["id1", "id2", "fatContent", "similarCow", "flavor"], cheese_field.typed_children[CheeseType].keys
|
133
|
-
assert_equal ["fatContent", "origin"], cheese_field.typed_children[EdibleInterface].keys
|
131
|
+
cheese_field = op_node.typed_children[Dummy::DairyAppQueryType]["cheese"]
|
132
|
+
assert_equal ["id1", "id2", "fatContent", "similarCow", "flavor"], cheese_field.typed_children[Dummy::CheeseType].keys
|
133
|
+
assert_equal ["fatContent", "origin"], cheese_field.typed_children[Dummy::EdibleInterface].keys
|
134
134
|
# Merge:
|
135
|
-
similar_cow_field = cheese_field.typed_children[CheeseType]["similarCow"]
|
136
|
-
assert_equal ["similarCowSource", "fatContent", "similarCheese", "id"], similar_cow_field.typed_children[CheeseType].keys
|
135
|
+
similar_cow_field = cheese_field.typed_children[Dummy::CheeseType]["similarCow"]
|
136
|
+
assert_equal ["similarCowSource", "fatContent", "similarCheese", "id"], similar_cow_field.typed_children[Dummy::CheeseType].keys
|
137
137
|
# Deep merge:
|
138
|
-
similar_sheep_field = similar_cow_field.typed_children[CheeseType]["similarCheese"]
|
139
|
-
assert_equal ["flavor", "source"], similar_sheep_field.typed_children[CheeseType].keys
|
138
|
+
similar_sheep_field = similar_cow_field.typed_children[Dummy::CheeseType]["similarCheese"]
|
139
|
+
assert_equal ["flavor", "source"], similar_sheep_field.typed_children[Dummy::CheeseType].keys
|
140
140
|
|
141
|
-
edible_origin_node = cheese_field.typed_children[EdibleInterface]["origin"]
|
142
|
-
assert_equal EdibleInterface.get_field("origin"), edible_origin_node.definition
|
143
|
-
assert_equal EdibleInterface, edible_origin_node.owner_type
|
141
|
+
edible_origin_node = cheese_field.typed_children[Dummy::EdibleInterface]["origin"]
|
142
|
+
assert_equal Dummy::EdibleInterface.get_field("origin"), edible_origin_node.definition
|
143
|
+
assert_equal Dummy::EdibleInterface, edible_origin_node.owner_type
|
144
144
|
|
145
|
-
edible_fat_content_node = cheese_field.typed_children[EdibleInterface]["fatContent"]
|
146
|
-
assert_equal EdibleInterface.get_field("fatContent"), edible_fat_content_node.definition
|
147
|
-
assert_equal EdibleInterface, edible_fat_content_node.owner_type
|
145
|
+
edible_fat_content_node = cheese_field.typed_children[Dummy::EdibleInterface]["fatContent"]
|
146
|
+
assert_equal Dummy::EdibleInterface.get_field("fatContent"), edible_fat_content_node.definition
|
147
|
+
assert_equal Dummy::EdibleInterface, edible_fat_content_node.owner_type
|
148
148
|
|
149
|
-
cheese_fat_content_node = cheese_field.typed_children[CheeseType]["fatContent"]
|
150
|
-
assert_equal CheeseType.get_field("fatContent"), cheese_fat_content_node.definition
|
151
|
-
assert_equal CheeseType, cheese_fat_content_node.owner_type
|
149
|
+
cheese_fat_content_node = cheese_field.typed_children[Dummy::CheeseType]["fatContent"]
|
150
|
+
assert_equal Dummy::CheeseType.get_field("fatContent"), cheese_fat_content_node.definition
|
151
|
+
assert_equal Dummy::CheeseType, cheese_fat_content_node.owner_type
|
152
152
|
|
153
|
-
cheese_flavor_node = cheese_field.typed_children[CheeseType]["flavor"]
|
154
|
-
assert_equal CheeseType.get_field("flavor"), cheese_flavor_node.definition
|
155
|
-
assert_equal CheeseType, cheese_flavor_node.owner_type
|
153
|
+
cheese_flavor_node = cheese_field.typed_children[Dummy::CheeseType]["flavor"]
|
154
|
+
assert_equal Dummy::CheeseType.get_field("flavor"), cheese_flavor_node.definition
|
155
|
+
assert_equal Dummy::CheeseType, cheese_flavor_node.owner_type
|
156
156
|
|
157
157
|
|
158
158
|
# nested spread inside fragment definition:
|
159
|
-
cheese_2_field = op_node.typed_children[DairyAppQueryType]["cheese2"].typed_children[CheeseType]["similarCheese"]
|
160
|
-
assert_equal ["id", "fatContent"], cheese_2_field.typed_children[CheeseType].keys
|
159
|
+
cheese_2_field = op_node.typed_children[Dummy::DairyAppQueryType]["cheese2"].typed_children[Dummy::CheeseType]["similarCheese"]
|
160
|
+
assert_equal ["id", "fatContent"], cheese_2_field.typed_children[Dummy::CheeseType].keys
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
164
|
describe "nested fields on typed fragments" do
|
165
|
-
let(:result) {
|
165
|
+
let(:result) { Dummy::Schema.execute(query_string) }
|
166
166
|
let(:query_string) {%|
|
167
167
|
{
|
168
168
|
allDairy {
|
@@ -18,7 +18,7 @@ describe GraphQL::Introspection::InputValueType do
|
|
18
18
|
}
|
19
19
|
}
|
20
20
|
|}
|
21
|
-
let(:result) {
|
21
|
+
let(:result) { Dummy::Schema.execute(query_string) }
|
22
22
|
|
23
23
|
it "exposes metadata about input objects, giving extra quotes for strings" do
|
24
24
|
expected = { "data" => {
|
@@ -42,7 +42,7 @@ describe GraphQL::Introspection::InputValueType do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
let(:cheese_type) {
|
45
|
-
|
45
|
+
Dummy::Schema.execute(%|
|
46
46
|
{
|
47
47
|
__type(name: "Cheese") {
|
48
48
|
fields {
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
describe "GraphQL::Introspection::INTROSPECTION_QUERY" do
|
5
5
|
let(:query_string) { GraphQL::Introspection::INTROSPECTION_QUERY }
|
6
|
-
let(:result) {
|
6
|
+
let(:result) { Dummy::Schema.execute(query_string) }
|
7
7
|
|
8
8
|
it "runs" do
|
9
9
|
assert(result["data"])
|
@@ -11,12 +11,12 @@ describe GraphQL::Introspection::SchemaType do
|
|
11
11
|
}
|
12
12
|
}
|
13
13
|
|}
|
14
|
-
let(:result) {
|
14
|
+
let(:result) { Dummy::Schema.execute(query_string) }
|
15
15
|
|
16
16
|
it "exposes the schema" do
|
17
17
|
expected = { "data" => {
|
18
18
|
"__schema" => {
|
19
|
-
"types" =>
|
19
|
+
"types" => Dummy::Schema.types.values.map { |t| t.name.nil? ? (p t; raise("no name for #{t}")) : {"name" => t.name} },
|
20
20
|
"queryType"=>{
|
21
21
|
"fields"=>[
|
22
22
|
{"name"=>"allDairy"},
|
@@ -12,7 +12,7 @@ describe GraphQL::Introspection::TypeType do
|
|
12
12
|
missingType: __type(name: "NotAType") { name }
|
13
13
|
}
|
14
14
|
|}
|
15
|
-
let(:result) {
|
15
|
+
let(:result) { Dummy::Schema.execute(query_string, context: {}, variables: {"cheeseId" => 2}) }
|
16
16
|
let(:cheese_fields) {[
|
17
17
|
{"name"=>"deeplyNullableCheese", "isDeprecated" => false, "type"=>{ "kind" => "OBJECT", "name" => "Cheese", "ofType" => nil}},
|
18
18
|
{"name"=>"flavor", "isDeprecated" => false, "type" => { "kind" => "NON_NULL", "name" => nil, "ofType" => { "name" => "String"}}},
|
@@ -38,7 +38,7 @@ describe GraphQL::Language::Parser do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "parses the test schema" do
|
41
|
-
schema =
|
41
|
+
schema = Dummy::Schema
|
42
42
|
schema_string = GraphQL::Schema::Printer.print_schema(schema)
|
43
43
|
document = subject.parse(schema_string)
|
44
44
|
assert_equal schema_string, document.to_query_string
|
@@ -5,7 +5,7 @@ describe GraphQL::NonNullType do
|
|
5
5
|
describe "when a non-null field returns null" do
|
6
6
|
it "nulls out the parent selection" do
|
7
7
|
query_string = %|{ cow { name cantBeNullButIs } }|
|
8
|
-
result =
|
8
|
+
result = Dummy::Schema.execute(query_string)
|
9
9
|
assert_equal({"cow" => nil }, result["data"])
|
10
10
|
assert_equal([{"message"=>"Cannot return null for non-nullable field Cow.cantBeNullButIs"}], result["errors"])
|
11
11
|
end
|
@@ -24,14 +24,14 @@ describe GraphQL::NonNullType do
|
|
24
24
|
}
|
25
25
|
}
|
26
26
|
|
|
27
|
-
result =
|
27
|
+
result = Dummy::Schema.execute(query_string)
|
28
28
|
assert_equal(nil, result["data"])
|
29
29
|
assert_equal([{"message"=>"Cannot return null for non-nullable field DeepNonNull.nonNullInt"}], result["errors"])
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "when type_error is configured to raise an error" do
|
33
33
|
it "crashes query execution" do
|
34
|
-
raise_schema =
|
34
|
+
raise_schema = Dummy::Schema.redefine {
|
35
35
|
type_error ->(type_err, ctx) {
|
36
36
|
raise type_err
|
37
37
|
}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe GraphQL::ObjectType do
|
5
|
-
let(:type) { CheeseType }
|
5
|
+
let(:type) { Dummy::CheeseType }
|
6
6
|
|
7
7
|
it "has a name" do
|
8
8
|
assert_equal("Cheese", type.name)
|
@@ -16,16 +16,16 @@ describe GraphQL::ObjectType do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "may have interfaces" do
|
19
|
-
assert_equal([EdibleInterface, AnimalProductInterface, LocalProductInterface], type.interfaces)
|
19
|
+
assert_equal([Dummy::EdibleInterface, Dummy::AnimalProductInterface, Dummy::LocalProductInterface], type.interfaces)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "accepts fields definition" do
|
23
|
-
last_produced_dairy = GraphQL::Field.define(name: :last_produced_dairy, type: DairyProductUnion)
|
23
|
+
last_produced_dairy = GraphQL::Field.define(name: :last_produced_dairy, type: Dummy::DairyProductUnion)
|
24
24
|
cow_type = GraphQL::ObjectType.define(name: "Cow", fields: [last_produced_dairy])
|
25
25
|
assert_equal([last_produced_dairy], cow_type.fields)
|
26
26
|
end
|
27
27
|
|
28
|
-
describe '#get_field
|
28
|
+
describe '#get_field' do
|
29
29
|
it "exposes fields" do
|
30
30
|
field = type.get_field("id")
|
31
31
|
assert_equal(GraphQL::TypeKinds::NON_NULL, field.type.kind)
|
@@ -33,15 +33,15 @@ describe GraphQL::ObjectType do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "exposes defined field property" do
|
36
|
-
field_without_prop = CheeseType.get_field("flavor")
|
37
|
-
field_with_prop = CheeseType.get_field("fatContent")
|
36
|
+
field_without_prop = Dummy::CheeseType.get_field("flavor")
|
37
|
+
field_with_prop = Dummy::CheeseType.get_field("fatContent")
|
38
38
|
assert_equal(field_without_prop.property, nil)
|
39
39
|
assert_equal(field_with_prop.property, :fat_content)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "looks up from interfaces" do
|
43
|
-
field_from_self = CheeseType.get_field("fatContent")
|
44
|
-
field_from_iface = MilkType.get_field("fatContent")
|
43
|
+
field_from_self = Dummy::CheeseType.get_field("fatContent")
|
44
|
+
field_from_iface = Dummy::MilkType.get_field("fatContent")
|
45
45
|
assert_equal(field_from_self.property, :fat_content)
|
46
46
|
assert_equal(field_from_iface.property, nil)
|
47
47
|
end
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
describe GraphQL::Query::Executor do
|
5
5
|
let(:operation_name) { nil }
|
6
|
-
let(:schema) {
|
6
|
+
let(:schema) { Dummy::Schema }
|
7
7
|
let(:variables) { {"cheeseId" => 2} }
|
8
8
|
let(:query) { GraphQL::Query.new(
|
9
9
|
schema,
|
@@ -77,16 +77,16 @@ describe GraphQL::Query::Executor do
|
|
77
77
|
DummyQueryType = GraphQL::ObjectType.define do
|
78
78
|
name "Query"
|
79
79
|
field :dairy do
|
80
|
-
type DairyType
|
80
|
+
type Dummy::DairyType
|
81
81
|
resolve ->(t, a, c) {
|
82
82
|
raise if resolved
|
83
83
|
resolved = true
|
84
|
-
DAIRY
|
84
|
+
Dummy::DAIRY
|
85
85
|
}
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
GraphQL::Schema.define(query: DummyQueryType, mutation:
|
89
|
+
GraphQL::Schema.define(query: DummyQueryType, mutation: Dummy::DairyAppMutationType, resolve_type: :pass, id_from_object: :pass)
|
90
90
|
}
|
91
91
|
let(:variables) { nil }
|
92
92
|
let(:query_string) { %|
|
@@ -3,14 +3,19 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
describe GraphQL::Query::Variables do
|
5
5
|
let(:query_string) {%|
|
6
|
-
query getCheese(
|
6
|
+
query getCheese(
|
7
|
+
$animals: [DairyAnimal!],
|
8
|
+
$intDefaultNull: Int = null,
|
9
|
+
$int: Int,
|
10
|
+
$intWithDefault: Int = 10)
|
11
|
+
{
|
7
12
|
cheese(id: 1) {
|
8
13
|
similarCheese(source: $animals)
|
9
14
|
}
|
10
15
|
}
|
11
16
|
|}
|
12
17
|
let(:ast_variables) { GraphQL.parse(query_string).definitions.first.variables }
|
13
|
-
let(:schema) {
|
18
|
+
let(:schema) { Dummy::Schema }
|
14
19
|
let(:variables) { GraphQL::Query::Variables.new(
|
15
20
|
schema,
|
16
21
|
GraphQL::Schema::Warden.new(schema.default_mask, schema: schema, context: nil),
|
@@ -57,7 +62,7 @@ describe GraphQL::Query::Variables do
|
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
60
|
-
describe "when a nullable list has a null in it" do
|
65
|
+
describe "when a non-nullable list has a null in it" do
|
61
66
|
let(:provided_variables) { { "ids" => [nil] } }
|
62
67
|
it "returns an error" do
|
63
68
|
assert_equal 1, result["errors"].length
|
@@ -71,13 +76,24 @@ describe GraphQL::Query::Variables do
|
|
71
76
|
{"int" => nil, "intWithDefault" => nil}
|
72
77
|
}
|
73
78
|
|
74
|
-
it "null
|
79
|
+
it "preserves explicit null" do
|
75
80
|
assert_equal nil, variables["int"]
|
81
|
+
assert_equal true, variables.key?("int")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "doesn't contain variables that weren't present" do
|
85
|
+
assert_equal nil, variables["animals"]
|
86
|
+
assert_equal false, variables.key?("animals")
|
76
87
|
end
|
77
88
|
|
78
89
|
it "preserves explicit null when variable has a default value" do
|
79
90
|
assert_equal nil, variables["intWithDefault"]
|
80
91
|
end
|
92
|
+
|
93
|
+
it "uses null default value" do
|
94
|
+
assert_equal nil, variables["intDefaultNull"]
|
95
|
+
assert_equal true, variables.key?("intDefaultNull")
|
96
|
+
end
|
81
97
|
end
|
82
98
|
end
|
83
99
|
end
|
data/spec/graphql/query_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe GraphQL::Query do
|
|
32
32
|
let(:operation_name) { nil }
|
33
33
|
let(:max_depth) { nil }
|
34
34
|
let(:query_variables) { {"cheeseId" => 2} }
|
35
|
-
let(:schema) {
|
35
|
+
let(:schema) { Dummy::Schema }
|
36
36
|
let(:document) { GraphQL.parse(query_string) }
|
37
37
|
|
38
38
|
let(:query) { GraphQL::Query.new(
|
@@ -132,7 +132,7 @@ describe GraphQL::Query do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
let(:schema) {
|
135
|
-
|
135
|
+
Dummy::Schema.redefine {
|
136
136
|
instrument(:query, Instrumenter)
|
137
137
|
}
|
138
138
|
}
|
@@ -334,6 +334,24 @@ describe GraphQL::Query do
|
|
334
334
|
end
|
335
335
|
end
|
336
336
|
|
337
|
+
describe "when they are non-null and provided a null value" do
|
338
|
+
let(:query_variables) { { "cheeseId" => nil } }
|
339
|
+
|
340
|
+
it "raises an error" do
|
341
|
+
expected = {
|
342
|
+
"errors" => [
|
343
|
+
{
|
344
|
+
"message" => "Variable cheeseId of type Int! was provided invalid value",
|
345
|
+
"locations" => [{"line" => 2, "column" => 23}],
|
346
|
+
"value" => nil,
|
347
|
+
"problems" => [{ "path" => [], "explanation" => "Expected value to not be null" }]
|
348
|
+
}
|
349
|
+
]
|
350
|
+
}
|
351
|
+
assert_equal(expected, result)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
337
355
|
describe "when they're a string" do
|
338
356
|
let(:query_variables) { '{ "var" : 1 }' }
|
339
357
|
it "raises an error" do
|
@@ -31,7 +31,7 @@ describe GraphQL::Relay::ConnectionType do
|
|
31
31
|
assert_equal 'basesWithCustomEdge', bases["fieldName"]
|
32
32
|
assert_equal ["YAVIN", "ECHO BASE", "SECRET HIDEOUT"] , bases["edges"].map { |e| e["upcasedName"] }
|
33
33
|
assert_equal ["Yavin", "Echo Base", "Secret Hideout"] , bases["edges"].map { |e| e["node"]["name"] }
|
34
|
-
assert_equal ["CustomBaseEdge"] , bases["edges"].map { |e| e["edgeClassName"] }.uniq
|
34
|
+
assert_equal ["StarWars::CustomBaseEdge"] , bases["edges"].map { |e| e["edgeClassName"] }.uniq
|
35
35
|
upcased_rebels_name = "ALLIANCE TO RESTORE THE REPUBLIC"
|
36
36
|
assert_equal [upcased_rebels_name] , bases["edges"].map { |e| e["upcasedParentName"] }.uniq
|
37
37
|
end
|
@@ -22,8 +22,8 @@ describe GraphQL::Relay::Mutation do
|
|
22
22
|
|}
|
23
23
|
|
24
24
|
after do
|
25
|
-
|
26
|
-
|
25
|
+
StarWars::DATA["Ship"].delete("9")
|
26
|
+
StarWars::DATA["Faction"]["1"].ships.delete("9")
|
27
27
|
end
|
28
28
|
|
29
29
|
it "supports null values" do
|
@@ -38,7 +38,7 @@ describe GraphQL::Relay::Mutation do
|
|
38
38
|
"id" => GraphQL::Schema::UniqueWithinType.encode("Ship", "9"),
|
39
39
|
},
|
40
40
|
},
|
41
|
-
"faction" => {"name" =>
|
41
|
+
"faction" => {"name" => StarWars::DATA["Faction"]["1"].name }
|
42
42
|
}
|
43
43
|
}}
|
44
44
|
assert_equal(expected, result)
|
@@ -60,7 +60,7 @@ describe GraphQL::Relay::Mutation do
|
|
60
60
|
"id" => GraphQL::Schema::UniqueWithinType.encode("Ship", "9"),
|
61
61
|
},
|
62
62
|
},
|
63
|
-
"faction" => {"name" =>
|
63
|
+
"faction" => {"name" => StarWars::DATA["Faction"]["1"].name }
|
64
64
|
}
|
65
65
|
}}
|
66
66
|
assert_equal(expected, result)
|
@@ -73,14 +73,14 @@ describe GraphQL::Relay::Mutation do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "applies the description to the derived field" do
|
76
|
-
assert_equal "Add a ship to this faction", IntroduceShipMutation.field.description
|
76
|
+
assert_equal "Add a ship to this faction", StarWars::IntroduceShipMutation.field.description
|
77
77
|
end
|
78
78
|
|
79
79
|
it "inserts itself into the derived objects' metadata" do
|
80
|
-
assert_equal IntroduceShipMutation, IntroduceShipMutation.field.mutation
|
81
|
-
assert_equal IntroduceShipMutation, IntroduceShipMutation.return_type.mutation
|
82
|
-
assert_equal IntroduceShipMutation, IntroduceShipMutation.input_type.mutation
|
83
|
-
assert_equal IntroduceShipMutation, IntroduceShipMutation.result_class.mutation
|
80
|
+
assert_equal StarWars::IntroduceShipMutation, StarWars::IntroduceShipMutation.field.mutation
|
81
|
+
assert_equal StarWars::IntroduceShipMutation, StarWars::IntroduceShipMutation.return_type.mutation
|
82
|
+
assert_equal StarWars::IntroduceShipMutation, StarWars::IntroduceShipMutation.input_type.mutation
|
83
|
+
assert_equal StarWars::IntroduceShipMutation, StarWars::IntroduceShipMutation.result_class.mutation
|
84
84
|
end
|
85
85
|
|
86
86
|
describe "aliased methods" do
|