Skip to content

Commit 0e092de

Browse files
authored
Merge pull request #5382 from gmac/gmac/inherit_validation_allowances
Inherit validation allowances
2 parents 1d72531 + 9a6498b commit 0e092de

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

lib/graphql/schema.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,11 @@ def did_you_mean(new_dym = NOT_CONFIGURED)
16951695
# @return [true, false, nil]
16961696
def allow_legacy_invalid_empty_selections_on_union(new_value = NOT_CONFIGURED)
16971697
if NOT_CONFIGURED.equal?(new_value)
1698-
@allow_legacy_invalid_empty_selections_on_union
1698+
if defined?(@allow_legacy_invalid_empty_selections_on_union)
1699+
@allow_legacy_invalid_empty_selections_on_union
1700+
else
1701+
find_inherited_value(:allow_legacy_invalid_empty_selections_on_union)
1702+
end
16991703
else
17001704
@allow_legacy_invalid_empty_selections_on_union = new_value
17011705
end
@@ -1726,7 +1730,11 @@ def legacy_invalid_empty_selections_on_union(query)
17261730
# @return [true, false, nil]
17271731
def allow_legacy_invalid_return_type_conflicts(new_value = NOT_CONFIGURED)
17281732
if NOT_CONFIGURED.equal?(new_value)
1729-
@allow_legacy_invalid_return_type_conflicts
1733+
if defined?(@allow_legacy_invalid_return_type_conflicts)
1734+
@allow_legacy_invalid_return_type_conflicts
1735+
else
1736+
find_inherited_value(:allow_legacy_invalid_return_type_conflicts)
1737+
end
17301738
else
17311739
@allow_legacy_invalid_return_type_conflicts = new_value
17321740
end
@@ -1774,7 +1782,11 @@ def legacy_invalid_return_type_conflicts(query, type1, type2, node1, node2)
17741782
# complexity_cost_calculation_mode(:compare)
17751783
def complexity_cost_calculation_mode(new_mode = NOT_CONFIGURED)
17761784
if NOT_CONFIGURED.equal?(new_mode)
1777-
@complexity_cost_calculation_mode
1785+
if defined?(@complexity_cost_calculation_mode)
1786+
@complexity_cost_calculation_mode
1787+
else
1788+
find_inherited_value(:complexity_cost_calculation_mode)
1789+
end
17781790
else
17791791
@complexity_cost_calculation_mode = new_mode
17801792
end

spec/graphql/analysis/query_complexity_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ def resolve
638638
}
639639
|}
640640

641+
it "inherits complexity_cost_calculation_mode" do
642+
schema = Class.new(CustomComplexityByMethodSchema)
643+
assert_equal CustomComplexityByMethodSchema.complexity_cost_calculation_mode, schema.complexity_cost_calculation_mode
644+
end
645+
641646
it "sums the complexity" do
642647
complexity = reduce_result.first
643648
# 10 from `complexity`, `0.3` from `value`

spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,16 @@ def self.legacy_invalid_empty_selections_on_union(query)
155155
assert_includes(errors.map { |e| e["message"] }, expected_err)
156156
end
157157
end
158+
159+
describe "With inherited setting" do
160+
let(:schema) { Class.new(Class.new(Dummy::Schema) {
161+
allow_legacy_invalid_empty_selections_on_union(true)
162+
})
163+
}
164+
165+
it "has correct value" do
166+
assert schema.allow_legacy_invalid_empty_selections_on_union
167+
end
168+
end
158169
end
159170
end

spec/graphql/static_validation/rules/fields_will_merge_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,12 @@ def self.legacy_invalid_return_type_conflicts(query, t1, t2, node1, node2)
10731073
}
10741074
assert_equal [expected_error], res.map(&:to_h)
10751075
end
1076+
1077+
it "inherits allow_legacy_invalid_empty_selections_on_union" do
1078+
base_schema = Class.new(schema) { allow_legacy_invalid_return_type_conflicts(true) }
1079+
ext_schema = Class.new(base_schema)
1080+
assert ext_schema.allow_legacy_invalid_return_type_conflicts
1081+
end
10761082
end
10771083

10781084
describe "conflicting list / non-list fields" do

0 commit comments

Comments
 (0)