graphql 1.5.4 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/define/instance_definable.rb +54 -29
- data/lib/graphql/enum_type.rb +0 -1
- data/lib/graphql/execution/execute.rb +15 -9
- data/lib/graphql/execution/field_result.rb +3 -6
- data/lib/graphql/execution/lazy/lazy_method_map.rb +66 -12
- data/lib/graphql/language.rb +15 -1
- data/lib/graphql/language/nodes.rb +17 -1
- data/lib/graphql/language/parser.rb +8 -8
- data/lib/graphql/language/parser.y +8 -8
- data/lib/graphql/query.rb +3 -4
- data/lib/graphql/query/literal_input.rb +2 -0
- data/lib/graphql/relay/mutation.rb +2 -3
- data/lib/graphql/schema.rb +1 -3
- data/lib/graphql/schema/loader.rb +26 -4
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/definition_dependencies.rb +0 -1
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +32 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +11 -5
- data/lib/graphql/static_validation/validation_context.rb +0 -1
- data/lib/graphql/version.rb +1 -1
- data/spec/graphql/define/instance_definable_spec.rb +21 -0
- data/spec/graphql/execution/execute_spec.rb +61 -0
- data/spec/graphql/execution/lazy/lazy_method_map_spec.rb +57 -0
- data/spec/graphql/input_object_type_spec.rb +2 -2
- data/spec/graphql/introspection/input_value_type_spec.rb +3 -1
- data/spec/graphql/introspection/type_type_spec.rb +1 -0
- data/spec/graphql/query_spec.rb +69 -10
- data/spec/graphql/schema/loader_spec.rb +7 -3
- data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +0 -1
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +6 -6
- data/spec/graphql/static_validation/rules/no_definitions_are_present_spec.rb +28 -0
- data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +17 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/support/dummy/schema.rb +11 -0
- data/spec/support/star_wars/data.rb +16 -2
- metadata +21 -30
@@ -104,6 +104,7 @@ describe GraphQL::Schema::Loader do
|
|
104
104
|
argument :varied, variant_input_type, default_value: { id: "123", int: 234, float: 2.3, enum: :foo, sub: [{ string: "str" }] }
|
105
105
|
argument :variedWithNull, variant_input_type_with_nulls, default_value: { id: nil, int: nil, float: nil, enum: nil, sub: nil, bigint: nil, bool: nil }
|
106
106
|
argument :enum, choice_type, default_value: :foo
|
107
|
+
argument :array, types[!types.String], default_value: ["foo", "bar"]
|
107
108
|
end
|
108
109
|
|
109
110
|
field :content do
|
@@ -223,10 +224,13 @@ describe GraphQL::Schema::Loader do
|
|
223
224
|
it "sets correct default values for complex field arguments" do
|
224
225
|
type = loaded_schema.types['Query']
|
225
226
|
field = type.fields['post']
|
226
|
-
arg = field.arguments['varied']
|
227
227
|
|
228
|
-
|
229
|
-
|
228
|
+
varied = field.arguments['varied']
|
229
|
+
assert_equal varied.default_value, { 'id' => "123", 'int' => 234, 'float' => 2.3, 'enum' => "FOO", 'sub' => [{ 'string' => "str" }] }
|
230
|
+
assert !varied.default_value.key?('bool'), 'Omits default value for unspecified arguments'
|
231
|
+
|
232
|
+
array = field.arguments['array']
|
233
|
+
assert_equal array.default_value, ["foo", "bar"]
|
230
234
|
end
|
231
235
|
|
232
236
|
it "does not set default value when there are none on input fields" do
|
@@ -156,7 +156,7 @@ describe GraphQL::StaticValidation::FieldsWillMerge do
|
|
156
156
|
|}
|
157
157
|
|
158
158
|
it "fails rule" do
|
159
|
-
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {
|
159
|
+
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {dogCommand:"SIT"} or {dogCommand:"$dogCommand"}?)], error_messages
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
@@ -171,7 +171,7 @@ describe GraphQL::StaticValidation::FieldsWillMerge do
|
|
171
171
|
|}
|
172
172
|
|
173
173
|
it "fails rule" do
|
174
|
-
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {
|
174
|
+
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {dogCommand:"$varOne"} or {dogCommand:"$varTwo"}?)], error_messages
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
@@ -246,7 +246,7 @@ describe GraphQL::StaticValidation::FieldsWillMerge do
|
|
246
246
|
|}
|
247
247
|
|
248
248
|
it "fails rule" do
|
249
|
-
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {} or {
|
249
|
+
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {} or {dogCommand:"HEEL"}?)], error_messages
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
@@ -261,7 +261,7 @@ describe GraphQL::StaticValidation::FieldsWillMerge do
|
|
261
261
|
|}
|
262
262
|
|
263
263
|
it "fails rule" do
|
264
|
-
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {
|
264
|
+
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {dogCommand:"SIT"} or {}?)], error_messages
|
265
265
|
end
|
266
266
|
end
|
267
267
|
|
@@ -276,7 +276,7 @@ describe GraphQL::StaticValidation::FieldsWillMerge do
|
|
276
276
|
|}
|
277
277
|
|
278
278
|
it "fails rule" do
|
279
|
-
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {
|
279
|
+
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {dogCommand:"SIT"} or {dogCommand:"HEEL"}?)], error_messages
|
280
280
|
end
|
281
281
|
end
|
282
282
|
|
@@ -291,7 +291,7 @@ describe GraphQL::StaticValidation::FieldsWillMerge do
|
|
291
291
|
|}
|
292
292
|
|
293
293
|
it "fails rule" do
|
294
|
-
assert_equal [%q(Field 'image' has an argument conflict: {
|
294
|
+
assert_equal [%q(Field 'image' has an argument conflict: {maxWidth:"10"} or {maxWidth:"20"}?)], error_messages
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe GraphQL::StaticValidation::NoDefinitionsArePresent do
|
5
|
+
include StaticValidationHelpers
|
6
|
+
describe "when schema definitions are present in the query" do
|
7
|
+
let(:query_string) {
|
8
|
+
<<-GRAPHQL
|
9
|
+
{
|
10
|
+
cheese(id: 1) { flavor }
|
11
|
+
}
|
12
|
+
|
13
|
+
type Thing {
|
14
|
+
stuff: Int
|
15
|
+
}
|
16
|
+
|
17
|
+
scalar Date
|
18
|
+
GRAPHQL
|
19
|
+
}
|
20
|
+
|
21
|
+
it "adds an error" do
|
22
|
+
assert_equal 1, errors.length
|
23
|
+
err = errors[0]
|
24
|
+
assert_equal "Query cannot contain schema definitions", err["message"]
|
25
|
+
assert_equal [{"line"=>5, "column"=>7}, {"line"=>9, "column"=>7}], err["locations"]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -63,4 +63,21 @@ describe GraphQL::StaticValidation::VariableUsagesAreAllowed do
|
|
63
63
|
]
|
64
64
|
assert_equal(expected, errors)
|
65
65
|
end
|
66
|
+
|
67
|
+
describe "input objects that are out of place" do
|
68
|
+
let(:query_string) { <<-GRAPHQL
|
69
|
+
query getCheese($id: ID!) {
|
70
|
+
cheese(id: {blah: $id} ) {
|
71
|
+
__typename @nonsense(id: {blah: $id})
|
72
|
+
nonsense(id: {blah: {blah: $id}})
|
73
|
+
}
|
74
|
+
}
|
75
|
+
GRAPHQL
|
76
|
+
}
|
77
|
+
|
78
|
+
it "adds an error" do
|
79
|
+
assert_equal 3, errors.length
|
80
|
+
assert_equal "Argument 'id' on Field 'cheese' has an invalid value. Expected type 'Int!'.", errors[0]["message"]
|
81
|
+
end
|
82
|
+
end
|
66
83
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,8 @@ require "codeclimate-test-reporter"
|
|
3
3
|
CodeClimate::TestReporter.start
|
4
4
|
require "rails/all"
|
5
5
|
require "rails/generators"
|
6
|
-
require "sqlite3"
|
6
|
+
require "jdbc/sqlite3" if RUBY_ENGINE == 'jruby'
|
7
|
+
require "sqlite3" if RUBY_ENGINE == 'ruby'
|
7
8
|
require "sequel"
|
8
9
|
require "graphql"
|
9
10
|
require "benchmark"
|
@@ -168,6 +168,15 @@ module Dummy
|
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
|
+
ResourceOrderType = GraphQL::InputObjectType.define {
|
172
|
+
name "ResourceOrderType"
|
173
|
+
description "Properties used to determine ordering"
|
174
|
+
|
175
|
+
argument :direction, !types.String do
|
176
|
+
description "ASC or DESC"
|
177
|
+
end
|
178
|
+
}
|
179
|
+
|
171
180
|
DairyProductInputType = GraphQL::InputObjectType.define {
|
172
181
|
name "DairyProductInput"
|
173
182
|
description "Properties for finding a dairy product"
|
@@ -188,6 +197,8 @@ module Dummy
|
|
188
197
|
|
189
198
|
# ensure default can be false
|
190
199
|
input_field :organic, types.Boolean, default_value: false
|
200
|
+
|
201
|
+
input_field :order_by, -> { ResourceOrderType }, default_value: { direction: 'ASC' }
|
191
202
|
}
|
192
203
|
|
193
204
|
DeepNonNullType = GraphQL::ObjectType.define do
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'ostruct'
|
3
|
+
|
4
|
+
# platform helper
|
5
|
+
def jruby?
|
6
|
+
RUBY_ENGINE == 'jruby'
|
7
|
+
end
|
8
|
+
|
3
9
|
module StarWars
|
4
10
|
names = [
|
5
11
|
'X-Wing',
|
@@ -15,7 +21,11 @@ module StarWars
|
|
15
21
|
# ActiveRecord::Base.logger = Logger.new(STDOUT)
|
16
22
|
`rm -f ./_test_.db`
|
17
23
|
# Set up "Bases" in ActiveRecord
|
18
|
-
|
24
|
+
if jruby?
|
25
|
+
ActiveRecord::Base.establish_connection(adapter: "jdbcsqlite3", database: "./_test_.db")
|
26
|
+
else
|
27
|
+
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "./_test_.db")
|
28
|
+
end
|
19
29
|
|
20
30
|
ActiveRecord::Schema.define do
|
21
31
|
self.verbose = false
|
@@ -37,7 +47,11 @@ module StarWars
|
|
37
47
|
Base.create!(name: "Headquarters", planet: "Coruscant", faction_id: 2)
|
38
48
|
|
39
49
|
# Also, set up Bases with Sequel
|
40
|
-
DB =
|
50
|
+
DB = if jruby?
|
51
|
+
Sequel.connect('jdbc:sqlite:./_test_.db')
|
52
|
+
else
|
53
|
+
Sequel.sqlite("./_test_.db")
|
54
|
+
end
|
41
55
|
class SequelBase < Sequel::Model(:bases)
|
42
56
|
end
|
43
57
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: concurrent-ruby
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: guard
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,20 +234,6 @@ dependencies:
|
|
220
234
|
- - "~>"
|
221
235
|
- !ruby/object:Gem::Version
|
222
236
|
version: '0.45'
|
223
|
-
- !ruby/object:Gem::Dependency
|
224
|
-
name: ruby-prof
|
225
|
-
requirement: !ruby/object:Gem::Requirement
|
226
|
-
requirements:
|
227
|
-
- - ">="
|
228
|
-
- !ruby/object:Gem::Version
|
229
|
-
version: '0'
|
230
|
-
type: :development
|
231
|
-
prerelease: false
|
232
|
-
version_requirements: !ruby/object:Gem::Requirement
|
233
|
-
requirements:
|
234
|
-
- - ">="
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
version: '0'
|
237
237
|
- !ruby/object:Gem::Dependency
|
238
238
|
name: appraisal
|
239
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -262,20 +262,6 @@ dependencies:
|
|
262
262
|
- - ">="
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: '0'
|
265
|
-
- !ruby/object:Gem::Dependency
|
266
|
-
name: sqlite3
|
267
|
-
requirement: !ruby/object:Gem::Requirement
|
268
|
-
requirements:
|
269
|
-
- - ">="
|
270
|
-
- !ruby/object:Gem::Version
|
271
|
-
version: '0'
|
272
|
-
type: :development
|
273
|
-
prerelease: false
|
274
|
-
version_requirements: !ruby/object:Gem::Requirement
|
275
|
-
requirements:
|
276
|
-
- - ">="
|
277
|
-
- !ruby/object:Gem::Version
|
278
|
-
version: '0'
|
279
265
|
- !ruby/object:Gem::Dependency
|
280
266
|
name: github-pages
|
281
267
|
requirement: !ruby/object:Gem::Requirement
|
@@ -489,6 +475,7 @@ files:
|
|
489
475
|
- lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb
|
490
476
|
- lib/graphql/static_validation/rules/fragments_are_used.rb
|
491
477
|
- lib/graphql/static_validation/rules/mutation_root_exists.rb
|
478
|
+
- lib/graphql/static_validation/rules/no_definitions_are_present.rb
|
492
479
|
- lib/graphql/static_validation/rules/operation_names_are_valid.rb
|
493
480
|
- lib/graphql/static_validation/rules/required_arguments_are_present.rb
|
494
481
|
- lib/graphql/static_validation/rules/subscription_root_exists.rb
|
@@ -533,6 +520,7 @@ files:
|
|
533
520
|
- spec/graphql/directive_spec.rb
|
534
521
|
- spec/graphql/enum_type_spec.rb
|
535
522
|
- spec/graphql/execution/execute_spec.rb
|
523
|
+
- spec/graphql/execution/lazy/lazy_method_map_spec.rb
|
536
524
|
- spec/graphql/execution/lazy_spec.rb
|
537
525
|
- spec/graphql/execution/typecast_spec.rb
|
538
526
|
- spec/graphql/execution_error_spec.rb
|
@@ -604,6 +592,7 @@ files:
|
|
604
592
|
- spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
|
605
593
|
- spec/graphql/static_validation/rules/fragments_are_used_spec.rb
|
606
594
|
- spec/graphql/static_validation/rules/mutation_root_exists_spec.rb
|
595
|
+
- spec/graphql/static_validation/rules/no_definitions_are_present_spec.rb
|
607
596
|
- spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
|
608
597
|
- spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb
|
609
598
|
- spec/graphql/static_validation/rules/subscription_root_exists_spec.rb
|
@@ -676,6 +665,7 @@ test_files:
|
|
676
665
|
- spec/graphql/directive_spec.rb
|
677
666
|
- spec/graphql/enum_type_spec.rb
|
678
667
|
- spec/graphql/execution/execute_spec.rb
|
668
|
+
- spec/graphql/execution/lazy/lazy_method_map_spec.rb
|
679
669
|
- spec/graphql/execution/lazy_spec.rb
|
680
670
|
- spec/graphql/execution/typecast_spec.rb
|
681
671
|
- spec/graphql/execution_error_spec.rb
|
@@ -747,6 +737,7 @@ test_files:
|
|
747
737
|
- spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb
|
748
738
|
- spec/graphql/static_validation/rules/fragments_are_used_spec.rb
|
749
739
|
- spec/graphql/static_validation/rules/mutation_root_exists_spec.rb
|
740
|
+
- spec/graphql/static_validation/rules/no_definitions_are_present_spec.rb
|
750
741
|
- spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
|
751
742
|
- spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb
|
752
743
|
- spec/graphql/static_validation/rules/subscription_root_exists_spec.rb
|