graphql 1.5.5 → 1.5.6
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.rb +1 -2
- data/lib/graphql/analysis/query_complexity.rb +0 -1
- data/lib/graphql/argument.rb +43 -3
- data/lib/graphql/base_type.rb +50 -7
- data/lib/graphql/boolean_type.rb +2 -2
- data/lib/graphql/compatibility/execution_specification.rb +1 -1
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +2 -2
- data/lib/graphql/compatibility/lazy_execution_specification.rb +1 -1
- data/lib/graphql/enum_type.rb +35 -27
- data/lib/graphql/execution/execute.rb +3 -5
- data/lib/graphql/execution/lazy/lazy_method_map.rb +2 -2
- data/lib/graphql/float_type.rb +2 -2
- data/lib/graphql/function.rb +5 -0
- data/lib/graphql/id_type.rb +2 -2
- data/lib/graphql/input_object_type.rb +46 -36
- data/lib/graphql/int_type.rb +2 -2
- data/lib/graphql/introspection/input_value_type.rb +1 -1
- data/lib/graphql/list_type.rb +17 -17
- data/lib/graphql/non_null_type.rb +6 -11
- data/lib/graphql/query.rb +2 -2
- data/lib/graphql/query/literal_input.rb +15 -8
- data/lib/graphql/query/null_context.rb +29 -0
- data/lib/graphql/query/serial_execution/value_resolution.rb +2 -4
- data/lib/graphql/query/variables.rb +9 -7
- data/lib/graphql/relay/mutation.rb +6 -7
- data/lib/graphql/scalar_type.rb +54 -19
- data/lib/graphql/schema.rb +21 -5
- data/lib/graphql/schema/build_from_definition.rb +3 -1
- data/lib/graphql/schema/catchall_middleware.rb +1 -1
- data/lib/graphql/schema/default_type_error.rb +1 -1
- data/lib/graphql/schema/loader.rb +2 -2
- data/lib/graphql/schema/printer.rb +1 -1
- data/lib/graphql/schema/validation.rb +1 -2
- data/lib/graphql/static_validation/arguments_validator.rb +1 -1
- data/lib/graphql/static_validation/literal_validator.rb +5 -4
- data/lib/graphql/static_validation/rules/operation_names_are_valid.rb +1 -1
- data/lib/graphql/static_validation/validation_context.rb +1 -1
- data/lib/graphql/string_encoding_error.rb +10 -0
- data/lib/graphql/string_type.rb +8 -3
- data/lib/graphql/version.rb +1 -1
- data/spec/graphql/argument_spec.rb +13 -0
- data/spec/graphql/base_type_spec.rb +1 -1
- data/spec/graphql/boolean_type_spec.rb +1 -1
- data/spec/graphql/enum_type_spec.rb +11 -11
- data/spec/graphql/field_spec.rb +1 -1
- data/spec/graphql/float_type_spec.rb +4 -4
- data/spec/graphql/function_spec.rb +5 -4
- data/spec/graphql/input_object_type_spec.rb +28 -20
- data/spec/graphql/int_type_spec.rb +4 -4
- data/spec/graphql/language/lexer_spec.rb +0 -1
- data/spec/graphql/list_type_spec.rb +3 -3
- data/spec/graphql/query/literal_input_spec.rb +51 -0
- data/spec/graphql/query/variables_spec.rb +8 -4
- data/spec/graphql/relay/array_connection_spec.rb +1 -1
- data/spec/graphql/relay/page_info_spec.rb +1 -1
- data/spec/graphql/relay/relation_connection_spec.rb +3 -3
- data/spec/graphql/scalar_type_spec.rb +8 -8
- data/spec/graphql/schema/build_from_definition_spec.rb +2 -2
- data/spec/graphql/schema/loader_spec.rb +4 -4
- data/spec/graphql/string_type_spec.rb +33 -6
- data/spec/spec_helper.rb +0 -11
- data/spec/support/dummy/schema.rb +1 -1
- metadata +6 -2
@@ -4,13 +4,13 @@ require "spec_helper"
|
|
4
4
|
describe GraphQL::INT_TYPE do
|
5
5
|
describe "coerce_input" do
|
6
6
|
it "accepts ints and floats" do
|
7
|
-
assert_equal 1, GraphQL::INT_TYPE.
|
8
|
-
assert_equal 6, GraphQL::INT_TYPE.
|
7
|
+
assert_equal 1, GraphQL::INT_TYPE.coerce_isolated_input(1)
|
8
|
+
assert_equal 6, GraphQL::INT_TYPE.coerce_isolated_input(6.1)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "rejects other types" do
|
12
|
-
assert_equal nil, GraphQL::INT_TYPE.
|
13
|
-
assert_equal nil, GraphQL::INT_TYPE.
|
12
|
+
assert_equal nil, GraphQL::INT_TYPE.coerce_isolated_input("55")
|
13
|
+
assert_equal nil, GraphQL::INT_TYPE.coerce_isolated_input(true)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -5,12 +5,12 @@ describe GraphQL::ListType do
|
|
5
5
|
let(:float_list) { GraphQL::ListType.new(of_type: GraphQL::FLOAT_TYPE) }
|
6
6
|
|
7
7
|
it "coerces elements in the list" do
|
8
|
-
assert_equal([1.0, 2.0, 3.0].inspect, float_list.
|
8
|
+
assert_equal([1.0, 2.0, 3.0].inspect, float_list.coerce_isolated_input([1, 2, 3]).inspect)
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "validate_input with bad input" do
|
12
12
|
let(:bad_num) { "bad_num" }
|
13
|
-
let(:result) { float_list.
|
13
|
+
let(:result) { float_list.validate_isolated_input([bad_num, 2.0, 3.0]) }
|
14
14
|
|
15
15
|
it "returns an invalid result" do
|
16
16
|
assert(!result.valid?)
|
@@ -25,7 +25,7 @@ describe GraphQL::ListType do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "has the correct explanation" do
|
28
|
-
expected = GraphQL::FLOAT_TYPE.
|
28
|
+
expected = GraphQL::FLOAT_TYPE.validate_isolated_input(bad_num).problems[0]["explanation"]
|
29
29
|
actual = result.problems[0]["explanation"]
|
30
30
|
assert_equal(actual, expected)
|
31
31
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe GraphQL::Query::LiteralInput do
|
5
|
+
describe ".from_arguments" do
|
6
|
+
describe "arguments are prepared" do
|
7
|
+
let(:schema) {
|
8
|
+
query = GraphQL::ObjectType.define do
|
9
|
+
name "Query"
|
10
|
+
|
11
|
+
field :addOneToArgumentValue do
|
12
|
+
type !types.Int
|
13
|
+
argument :value do
|
14
|
+
type !types.Int
|
15
|
+
prepare ->(arg) do
|
16
|
+
return GraphQL::ExecutionError.new("Can't return more than 3 digits") if arg > 998
|
17
|
+
arg + 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
resolve ->(t, a, c) { a[:value] }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
GraphQL::Schema.define(query: query)
|
25
|
+
}
|
26
|
+
|
27
|
+
it "prepares values from query literals" do
|
28
|
+
result = schema.execute("{ addOneToArgumentValue(value: 1) }")
|
29
|
+
assert_equal(result["data"]["addOneToArgumentValue"], 2)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "prepares values from variables" do
|
33
|
+
result = schema.execute("query ($value: Int!) { addOneToArgumentValue(value: $value) }", variables: { "value" => 1} )
|
34
|
+
assert_equal(result["data"]["addOneToArgumentValue"], 2)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "prepares values correctly if called multiple times with different arguments" do
|
38
|
+
result = schema.execute("{ first: addOneToArgumentValue(value: 1) second: addOneToArgumentValue(value: 2) }")
|
39
|
+
assert_equal(result["data"]["first"], 2)
|
40
|
+
assert_equal(result["data"]["second"], 3)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "adds message to errors key if an ExecutionError is returned from the prepare function" do
|
44
|
+
result = schema.execute("{ addOneToArgumentValue(value: 999) }")
|
45
|
+
assert_equal(result["errors"][0]["message"], "Can't return more than 3 digits")
|
46
|
+
assert_equal(result["errors"][0]["locations"][0]["line"], 1)
|
47
|
+
assert_equal(result["errors"][0]["locations"][0]["column"], 25)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -17,8 +17,10 @@ describe GraphQL::Query::Variables do
|
|
17
17
|
let(:ast_variables) { GraphQL.parse(query_string).definitions.first.variables }
|
18
18
|
let(:schema) { Dummy::Schema }
|
19
19
|
let(:variables) { GraphQL::Query::Variables.new(
|
20
|
-
|
21
|
-
|
20
|
+
OpenStruct.new({
|
21
|
+
schema: schema,
|
22
|
+
warden: GraphQL::Schema::Warden.new(schema.default_mask, schema: schema, context: nil),
|
23
|
+
}),
|
22
24
|
ast_variables,
|
23
25
|
provided_variables)
|
24
26
|
}
|
@@ -165,8 +167,10 @@ describe GraphQL::Query::Variables do
|
|
165
167
|
let(:run_query) { schema.execute(query_string, variables: provided_variables) }
|
166
168
|
|
167
169
|
let(:variables) { GraphQL::Query::Variables.new(
|
168
|
-
|
169
|
-
|
170
|
+
OpenStruct.new({
|
171
|
+
schema: schema,
|
172
|
+
warden: GraphQL::Schema::Warden.new(schema.default_mask, schema: schema, context: nil),
|
173
|
+
}),
|
170
174
|
ast_variables,
|
171
175
|
provided_variables)
|
172
176
|
}
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
describe GraphQL::Relay::ArrayConnection do
|
5
5
|
def get_names(result)
|
6
6
|
ships = result["data"]["rebels"]["ships"]["edges"]
|
7
|
-
|
7
|
+
ships.map { |e| e["node"]["name"] }
|
8
8
|
end
|
9
9
|
|
10
10
|
def get_last_cursor(result)
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
describe GraphQL::Relay::RelationConnection do
|
5
5
|
def get_names(result)
|
6
6
|
ships = result["data"]["empire"]["bases"]["edges"]
|
7
|
-
|
7
|
+
ships.map { |e| e["node"]["name"] }
|
8
8
|
end
|
9
9
|
|
10
10
|
def get_page_info(result)
|
@@ -253,7 +253,7 @@ describe GraphQL::Relay::RelationConnection do
|
|
253
253
|
|
254
254
|
def get_names(result, field_name)
|
255
255
|
bases = result["data"]["empire"][field_name]["edges"]
|
256
|
-
|
256
|
+
bases.map { |b| b["node"]["name"] }
|
257
257
|
end
|
258
258
|
|
259
259
|
it "applies the default value" do
|
@@ -269,7 +269,7 @@ describe GraphQL::Relay::RelationConnection do
|
|
269
269
|
describe "with a Sequel::Dataset" do
|
270
270
|
def get_names(result)
|
271
271
|
ships = result["data"]["empire"]["basesAsSequelDataset"]["edges"]
|
272
|
-
|
272
|
+
ships.map { |e| e["node"]["name"] }
|
273
273
|
end
|
274
274
|
|
275
275
|
def get_page_info(result)
|
@@ -5,8 +5,8 @@ describe GraphQL::ScalarType do
|
|
5
5
|
let(:custom_scalar) {
|
6
6
|
GraphQL::ScalarType.define do
|
7
7
|
name "BigInt"
|
8
|
-
coerce_input ->(value) { value =~ /\d+/ ? Integer(value) : nil }
|
9
|
-
coerce_result ->(value) { value.to_s }
|
8
|
+
coerce_input ->(value, _ctx) { value =~ /\d+/ ? Integer(value) : nil }
|
9
|
+
coerce_result ->(value, _ctx) { value.to_s }
|
10
10
|
end
|
11
11
|
}
|
12
12
|
let(:bignum) { 2 ** 128 }
|
@@ -16,19 +16,19 @@ describe GraphQL::ScalarType do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "coerces nil into nil" do
|
19
|
-
assert_equal(nil, custom_scalar.
|
19
|
+
assert_equal(nil, custom_scalar.coerce_isolated_input(nil))
|
20
20
|
end
|
21
21
|
|
22
22
|
it "coerces input into objects" do
|
23
|
-
assert_equal(bignum, custom_scalar.
|
23
|
+
assert_equal(bignum, custom_scalar.coerce_isolated_input(bignum.to_s))
|
24
24
|
end
|
25
25
|
|
26
26
|
it "coerces result value for serialization" do
|
27
|
-
assert_equal(bignum.to_s, custom_scalar.
|
27
|
+
assert_equal(bignum.to_s, custom_scalar.coerce_isolated_result(bignum))
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "custom scalar errors" do
|
31
|
-
let(:result) { custom_scalar.
|
31
|
+
let(:result) { custom_scalar.validate_isolated_input("xyz") }
|
32
32
|
|
33
33
|
it "returns an invalid result" do
|
34
34
|
assert !result.valid?
|
@@ -37,7 +37,7 @@ describe GraphQL::ScalarType do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "validate_input with good input" do
|
40
|
-
let(:result) { GraphQL::INT_TYPE.
|
40
|
+
let(:result) { GraphQL::INT_TYPE.validate_isolated_input(150) }
|
41
41
|
|
42
42
|
it "returns a valid result" do
|
43
43
|
assert(result.valid?)
|
@@ -45,7 +45,7 @@ describe GraphQL::ScalarType do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "validate_input with bad input" do
|
48
|
-
let(:result) { GraphQL::INT_TYPE.
|
48
|
+
let(:result) { GraphQL::INT_TYPE.validate_isolated_input("bad num") }
|
49
49
|
|
50
50
|
it "returns an invalid result for bad input" do
|
51
51
|
assert(!result.valid?)
|
@@ -352,8 +352,8 @@ type Root {
|
|
352
352
|
|
353
353
|
built_schema = build_schema_and_compare_output(schema.chop)
|
354
354
|
custom_scalar = built_schema.types["CustomScalar"]
|
355
|
-
assert_equal true, custom_scalar.
|
356
|
-
assert_equal true, custom_scalar.
|
355
|
+
assert_equal true, custom_scalar.valid_isolated_input?("anything")
|
356
|
+
assert_equal true, custom_scalar.valid_isolated_input?(12345)
|
357
357
|
end
|
358
358
|
|
359
359
|
it 'supports input object' do
|
@@ -23,8 +23,8 @@ describe GraphQL::Schema::Loader do
|
|
23
23
|
|
24
24
|
big_int_type = GraphQL::ScalarType.define do
|
25
25
|
name "BigInt"
|
26
|
-
coerce_input ->(value) { value =~ /\d+/ ? Integer(value) : nil }
|
27
|
-
coerce_result ->(value) { value.to_s }
|
26
|
+
coerce_input ->(value, _ctx) { value =~ /\d+/ ? Integer(value) : nil }
|
27
|
+
coerce_result ->(value, _ctx) { value.to_s }
|
28
28
|
end
|
29
29
|
|
30
30
|
variant_input_type = GraphQL::InputObjectType.define do
|
@@ -202,8 +202,8 @@ describe GraphQL::Schema::Loader do
|
|
202
202
|
|
203
203
|
it "has no-op coerce functions" do
|
204
204
|
custom_scalar = loaded_schema.types["BigInt"]
|
205
|
-
assert_equal true, custom_scalar.
|
206
|
-
assert_equal true, custom_scalar.
|
205
|
+
assert_equal true, custom_scalar.valid_isolated_input?("anything")
|
206
|
+
assert_equal true, custom_scalar.valid_isolated_input?(12345)
|
207
207
|
end
|
208
208
|
|
209
209
|
it "sets correct default values on custom scalar arguments" do
|
@@ -9,21 +9,48 @@ describe GraphQL::STRING_TYPE do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "coerce_result" do
|
12
|
+
let(:binary_str) { "\0\0\0foo\255\255\255".dup.force_encoding("BINARY") }
|
12
13
|
it "requires string to be encoded as UTF-8" do
|
13
|
-
|
14
|
-
|
14
|
+
err = assert_raises(GraphQL::StringEncodingError) {
|
15
|
+
string_type.coerce_isolated_result(binary_str)
|
16
|
+
}
|
17
|
+
|
18
|
+
assert_equal "String \"#{binary_str}\" was encoded as ASCII-8BIT! GraphQL requires UTF-8 encoding.", err.message
|
19
|
+
assert_equal binary_str, err.string
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "when the schema defines a custom hander" do
|
23
|
+
let(:schema) {
|
24
|
+
GraphQL::Schema.define do
|
25
|
+
query(GraphQL::ObjectType.define(name: "Query"))
|
26
|
+
type_error ->(err, ctx) {
|
27
|
+
ctx.errors << err
|
28
|
+
"🌾"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
}
|
32
|
+
|
33
|
+
let(:context) {
|
34
|
+
OpenStruct.new(schema: schema, errors: [])
|
35
|
+
}
|
36
|
+
|
37
|
+
it "calls the handler" do
|
38
|
+
assert_equal "🌾", string_type.coerce_result(binary_str, context)
|
39
|
+
err = context.errors.last
|
40
|
+
assert_instance_of GraphQL::StringEncodingError, err
|
41
|
+
end
|
15
42
|
end
|
16
43
|
end
|
17
44
|
|
18
45
|
describe "coerce_input" do
|
19
46
|
it "accepts strings" do
|
20
|
-
assert_equal "str", string_type.
|
47
|
+
assert_equal "str", string_type.coerce_isolated_input("str")
|
21
48
|
end
|
22
49
|
|
23
50
|
it "doesn't accept other types" do
|
24
|
-
assert_equal nil, string_type.
|
25
|
-
assert_equal nil, string_type.
|
26
|
-
assert_equal nil, string_type.
|
51
|
+
assert_equal nil, string_type.coerce_isolated_input(100)
|
52
|
+
assert_equal nil, string_type.coerce_isolated_input(true)
|
53
|
+
assert_equal nil, string_type.coerce_isolated_input(0.999)
|
27
54
|
end
|
28
55
|
end
|
29
56
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -27,17 +27,6 @@ GraphQL::Field.accepts_definitions(metadata: assign_metadata_key)
|
|
27
27
|
GraphQL::Argument.accepts_definitions(metadata: assign_metadata_key)
|
28
28
|
GraphQL::EnumType::EnumValue.accepts_definitions(metadata: assign_metadata_key)
|
29
29
|
|
30
|
-
# Can be used as a GraphQL::Schema::Warden for some purposes, but allows anything
|
31
|
-
module PermissiveWarden
|
32
|
-
def self.arguments(input_obj)
|
33
|
-
input_obj.arguments.values
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.enum_values(enum_type)
|
37
|
-
enum_type.values.values
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
30
|
# Can be used as a GraphQL::Schema::Warden for some purposes, but allows nothing
|
42
31
|
module NothingWarden
|
43
32
|
def self.enum_values(enum_type)
|
@@ -225,7 +225,7 @@ module Dummy
|
|
225
225
|
|
226
226
|
def call(obj, args, ctx)
|
227
227
|
id_string = args["id"].to_s # Cheese has Int type, Milk has ID type :(
|
228
|
-
|
228
|
+
_id, item = @data.find { |id, item| id.to_s == id_string }
|
229
229
|
item
|
230
230
|
end
|
231
231
|
end
|
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.6
|
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-
|
11
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -408,6 +408,7 @@ files:
|
|
408
408
|
- lib/graphql/query/executor.rb
|
409
409
|
- lib/graphql/query/input_validation_result.rb
|
410
410
|
- lib/graphql/query/literal_input.rb
|
411
|
+
- lib/graphql/query/null_context.rb
|
411
412
|
- lib/graphql/query/serial_execution.rb
|
412
413
|
- lib/graphql/query/serial_execution/field_resolution.rb
|
413
414
|
- lib/graphql/query/serial_execution/operation_resolution.rb
|
@@ -487,6 +488,7 @@ files:
|
|
487
488
|
- lib/graphql/static_validation/type_stack.rb
|
488
489
|
- lib/graphql/static_validation/validation_context.rb
|
489
490
|
- lib/graphql/static_validation/validator.rb
|
491
|
+
- lib/graphql/string_encoding_error.rb
|
490
492
|
- lib/graphql/string_type.rb
|
491
493
|
- lib/graphql/type_kinds.rb
|
492
494
|
- lib/graphql/union_type.rb
|
@@ -550,6 +552,7 @@ files:
|
|
550
552
|
- spec/graphql/query/arguments_spec.rb
|
551
553
|
- spec/graphql/query/context_spec.rb
|
552
554
|
- spec/graphql/query/executor_spec.rb
|
555
|
+
- spec/graphql/query/literal_input_spec.rb
|
553
556
|
- spec/graphql/query/serial_execution/value_resolution_spec.rb
|
554
557
|
- spec/graphql/query/variables_spec.rb
|
555
558
|
- spec/graphql/query_spec.rb
|
@@ -695,6 +698,7 @@ test_files:
|
|
695
698
|
- spec/graphql/query/arguments_spec.rb
|
696
699
|
- spec/graphql/query/context_spec.rb
|
697
700
|
- spec/graphql/query/executor_spec.rb
|
701
|
+
- spec/graphql/query/literal_input_spec.rb
|
698
702
|
- spec/graphql/query/serial_execution/value_resolution_spec.rb
|
699
703
|
- spec/graphql/query/variables_spec.rb
|
700
704
|
- spec/graphql/query_spec.rb
|