Skip to content

Commit 3b7325a

Browse files
committed
Update scalars for two-arg coerce functions
1 parent 53dd5f5 commit 3b7325a

File tree

10 files changed

+18
-18
lines changed

10 files changed

+18
-18
lines changed

lib/graphql/boolean_type.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
name "Boolean"
44
description "Represents `true` or `false` values."
55

6-
coerce_input ->(value) { (value == true || value == false) ? value : nil }
7-
coerce_result ->(value) { !!value }
6+
coerce_input ->(value, _ctx) { (value == true || value == false) ? value : nil }
7+
coerce_result ->(value, _ctx) { !!value }
88
default_scalar true
99
end

lib/graphql/compatibility/execution_specification/specification_schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def self.build(execution_strategy)
6161

6262
timestamp_type = GraphQL::ScalarType.define do
6363
name "Timestamp"
64-
coerce_input ->(value) { Time.at(value.to_i) }
65-
coerce_result ->(value) { value.to_i }
64+
coerce_input ->(value, _ctx) { Time.at(value.to_i) }
65+
coerce_result ->(value, _ctx) { value.to_i }
6666
end
6767

6868
named_entity_interface_type = GraphQL::InterfaceType.define do

lib/graphql/float_type.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
name "Float"
44
description "Represents signed double-precision fractional values as specified by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point)."
55

6-
coerce_input ->(value) { value.is_a?(Numeric) ? value.to_f : nil }
7-
coerce_result ->(value) { value.to_f }
6+
coerce_input ->(value, _ctx) { value.is_a?(Numeric) ? value.to_f : nil }
7+
coerce_result ->(value, _ctx) { value.to_f }
88
default_scalar true
99
end

lib/graphql/id_type.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
name "ID"
44
description "Represents a unique identifier that is Base64 obfuscated. It is often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"VXNlci0xMA==\"`) or integer (such as `4`) input value will be accepted as an ID."
55

6-
coerce_result ->(value) { value.to_s }
7-
coerce_input ->(value) {
6+
coerce_result ->(value, _ctx) { value.to_s }
7+
coerce_input ->(value, _ctx) {
88
case value
99
when String, Integer
1010
value.to_s

lib/graphql/int_type.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
name "Int"
44
description "Represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1."
55

6-
coerce_input ->(value) { value.is_a?(Numeric) ? value.to_i : nil }
7-
coerce_result ->(value) { value.to_i }
6+
coerce_input ->(value, _ctx) { value.is_a?(Numeric) ? value.to_i : nil }
7+
coerce_result ->(value, _ctx) { value.to_i }
88
default_scalar true
99
end

lib/graphql/schema/build_from_definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def build(document, default_resolve: DefaultResolve)
119119
raise(NotImplementedError, "Generated Schema cannot use Interface or Union types for execution.")
120120
}
121121

122-
NullScalarCoerce = ->(val) { val }
122+
NullScalarCoerce = ->(val, _ctx) { val }
123123

124124
def build_enum_type(enum_type_definition, type_resolver)
125125
GraphQL::EnumType.define(

lib/graphql/schema/loader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def load(introspection_result)
3737
raise(NotImplementedError, "This schema was loaded from string, so it can't resolve types for objects")
3838
}
3939

40-
NullScalarCoerce = ->(val) { val }
40+
NullScalarCoerce = ->(val, _ctx) { val }
4141

4242
class << self
4343
private

lib/graphql/string_type.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
name "String"
44
description "Represents textual data as UTF-8 character sequences. This type is most often used by GraphQL to represent free-form human-readable text."
55

6-
coerce_result ->(value) {
6+
coerce_result ->(value, _ctx) {
77
str = value.to_s
88
return str if str.encoding == Encoding::US_ASCII || str.encoding == Encoding::UTF_8
99
raise GraphQL::CoercionError.new("The string `#{str}` was encoded as #{str.encoding}! GraphQL requires all strings to be UTF-8 encoded.")
1010
}
1111

12-
coerce_input ->(value) { value.is_a?(String) ? value : nil }
12+
coerce_input ->(value, _ctx) { value.is_a?(String) ? value : nil }
1313
default_scalar true
1414
end

spec/graphql/scalar_type_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
let(:custom_scalar) {
66
GraphQL::ScalarType.define do
77
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 }
1010
end
1111
}
1212
let(:bignum) { 2 ** 128 }

spec/graphql/schema/loader_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
big_int_type = GraphQL::ScalarType.define do
2525
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 }
2828
end
2929

3030
variant_input_type = GraphQL::InputObjectType.define do

0 commit comments

Comments
 (0)