Skip to content

Commit

Permalink
Merge pull request #4846 from casperisfine/ruby-3.4-compat
Browse files Browse the repository at this point in the history
Fix compatibility with Ruby 3.4-dev
  • Loading branch information
rmosolgo authored Feb 16, 2024
2 parents 41a78fc + 5dc5021 commit cb78c85
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 21 deletions.
11 changes: 6 additions & 5 deletions graphql.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ Gem::Specification.new do |s|

s.files = Dir["{lib}/**/*", "MIT-LICENSE", "readme.md", ".yardopts"]

s.add_runtime_dependency "base64"

s.add_development_dependency "benchmark-ips"
s.add_development_dependency "concurrent-ruby", "~>1.0"
s.add_development_dependency "memory_profiler"
# Remove this limit when minitest-reports is compatible
# https://github.com/kern/minitest-reporters/pull/220
s.add_development_dependency "minitest", "~> 5.9.0"
s.add_development_dependency "minitest-focus", "~> 1.1"
s.add_development_dependency "minitest-reporters", "~>1.0"

s.add_development_dependency "minitest"
s.add_development_dependency "minitest-focus"
s.add_development_dependency "minitest-reporters"
s.add_development_dependency "rake"
s.add_development_dependency 'rake-compiler'
s.add_development_dependency "rubocop", "1.12" # for Ruby 2.4 enforcement
Expand Down
6 changes: 5 additions & 1 deletion lib/graphql/schema/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ def included(child_class)
end
elsif child_class < GraphQL::Schema::Object
# This is being included into an object type, make sure it's using `implements(...)`
backtrace_line = caller(0, 10).find { |line| line.include?("schema/member/has_interfaces.rb") && line.include?("in `implements'")}
backtrace_line = caller_locations(0, 10).find do |location|
location.base_label == "implements" &&
location.path.end_with?("schema/member/has_interfaces.rb")
end

if !backtrace_line
raise "Attach interfaces using `implements(#{self})`, not `include(#{self})`"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/dataloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ def request_all
"Nope (FiberErrorSchema::Query.requestAll, nil, {})",
]

assert_equal(nil, res["data"])
assert_nil(res["data"])
assert_equal(expected_errors, context[:errors].sort)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/execution/lazy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
}
}|

assert_equal(nil, res["data"])
assert_nil(res["data"])
assert_equal 1, res["errors"].length
end

Expand Down
4 changes: 2 additions & 2 deletions spec/graphql/non_null_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
|
result = Dummy::Schema.execute(query_string)
assert_equal(nil, result["data"])
assert_nil(result["data"])
assert_equal([{"message"=>"Cannot return null for non-nullable field DeepNonNull.nonNullInt"}], result["errors"])
end

Expand All @@ -41,7 +41,7 @@ def self.type_error(type_err, ctx)
assert_equal("Cannot return null for non-nullable field Cow.cantBeNullButIs", err.message)
assert_equal("Cow", err.parent_type.graphql_name)
assert_equal("cantBeNullButIs", err.field.name)
assert_equal(nil, err.value)
assert_nil(err.value)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/graphql/query/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def push_query_error
let(:context) { GraphQL::Query::Context.new(query: OpenStruct.new(schema: schema), values: nil, object: nil) }

it "returns returns nil and reports key? => false" do
assert_equal(nil, context[:some_key])
assert_nil(context[:some_key])
assert_equal(false, context.key?(:some_key))
assert_raises(KeyError) { context.fetch(:some_key) }
end
Expand All @@ -74,7 +74,7 @@ def push_query_error
let(:context) { GraphQL::Query::Context.new(query: OpenStruct.new(schema: schema), values: nil, object: nil) }

it "allows you to assign new contexts" do
assert_equal(nil, context[:some_key])
assert_nil(context[:some_key])
context[:some_key] = "wow!"
assert_equal("wow!", context[:some_key])
end
Expand Down Expand Up @@ -396,7 +396,7 @@ class ContextSchema < GraphQL::Schema
expected_key = :a
expected_value = :test

assert_equal(nil, context[expected_key])
assert_nil(context[expected_key])
assert_equal({}, context.to_h)
refute(context.key?(expected_key))
assert_raises(KeyError) { context.fetch(expected_key) }
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ def on_field(node, _parent)

schema.execute(query, variables: { 'id' => nil })
assert(expected_args.first.key?(:id))
assert_equal(nil, expected_args.first[:id])
assert_nil(expected_args.first[:id])
end

it 'sets argument to [nil] when [null] is passed' do
Expand Down
4 changes: 2 additions & 2 deletions spec/graphql/schema/enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ def empty_enum
it "coerces names to underlying values" do
assert_equal("YAK", enum.coerce_isolated_input("YAK"))
assert_equal(1, enum.coerce_isolated_input("COW"))
assert_equal(nil, enum.coerce_isolated_input("NONE"))
assert_nil(enum.coerce_isolated_input("NONE"))
end

it "coerces invalid names to nil" do
assert_equal(nil, enum.coerce_isolated_input("YAKKITY"))
assert_nil(enum.coerce_isolated_input("YAKKITY"))
end

it "coerces result values to value's value" do
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/schema/scalar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def self.coerce_result(value, _ctx)
end

it "coerces nil into nil" do
assert_equal(nil, custom_scalar.coerce_isolated_input(nil))
assert_nil(custom_scalar.coerce_isolated_input(nil))
end

it "coerces input into objects" do
Expand Down
4 changes: 2 additions & 2 deletions spec/graphql/subscriptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,13 @@ def to_param

# Let's see what GraphQL sent over the wire:
assert_equal({"str" => "Update", "int" => 1}, deliveries["1"][0]["data"]["payload"])
assert_equal(nil, deliveries["1"][0]["data"]["event"])
assert_nil(deliveries["1"][0]["data"]["event"])

# Trigger another field subscription
schema.subscriptions.trigger(:event, {}, OpenStruct.new(int: 1))

# Now we should get result for another field
assert_equal(nil, deliveries["1"][1]["data"]["payload"])
assert_nil(deliveries["1"][1]["data"]["payload"])
assert_equal({"int" => 1}, deliveries["1"][1]["data"]["event"])
end

Expand Down
4 changes: 2 additions & 2 deletions spec/graphql/types/iso_8601_date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ def parse_date(date_str, context: {})
"parseDateOptional" => nil
}
assert_equal(expected_res, res["data"])
assert_equal(nil, res["errors"])
assert_nil(res["errors"])

res = DateTest::Schema.execute(query_str, context: { raise_type_error: true })
expected_res = {
"parseDateOptional" => nil
}
assert_equal(expected_res, res["data"])
assert_equal(nil, res["errors"])
assert_nil(res["errors"])
end
end

Expand Down

0 comments on commit cb78c85

Please sign in to comment.