Skip to content

Commit cd84552

Browse files
committed
merge all but deps.
1 parent 20bac9d commit cd84552

File tree

11 files changed

+41
-44
lines changed

11 files changed

+41
-44
lines changed

lib/graphql/stitching/composer.rb

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ class Composer
2424
BASIC_VALUE_MERGER = ->(values_by_location, _info) { values_by_location.each_value.find { !_1.nil? } }
2525

2626
# @api private
27-
VISIBILITY_PROFILES_MERGER = ->(values_by_location, _info) { values_by_location.each_value.reduce(:&) }
28-
29-
# @api private
30-
# VISIBILITY_PROFILES_MERGER = begin
31-
# f = Class.new(Formatter) do
32-
# def merge_kwargs(values_by_location, _info)
33-
# values_by_location.each_value.reduce(:&)
34-
# end
35-
# end
36-
# f.new
37-
# end
27+
VISIBILITY_PROFILES_MERGER = begin
28+
f = Class.new(Formatter) do
29+
def merge_kwargs(values_by_location, _info)
30+
values_by_location.each_value.reduce(:&)
31+
end
32+
end
33+
f.new
34+
end
3835

3936
# @api private
4037
COMPOSITION_VALIDATORS = [
@@ -63,8 +60,6 @@ def initialize(
6360
subscription_name: "Subscription",
6461
visibility_profiles: [],
6562
deprecation_merger: nil,
66-
default_value_merger: nil,
67-
directive_kwarg_merger: nil,
6863
root_field_location_selector: nil,
6964
root_entrypoints: nil,
7065
formatter: nil
@@ -73,8 +68,6 @@ def initialize(
7368
@mutation_name = mutation_name
7469
@subscription_name = subscription_name
7570
@deprecation_merger = deprecation_merger || BASIC_VALUE_MERGER
76-
@default_value_merger = default_value_merger || BASIC_VALUE_MERGER
77-
@directive_kwarg_merger = directive_kwarg_merger || BASIC_VALUE_MERGER
7871
@root_field_location_selector = root_field_location_selector
7972
@root_entrypoints = root_entrypoints || {}
8073
@formatter = formatter || Formatter.new
@@ -434,12 +427,12 @@ def build_merged_arguments(type_name, members_by_location, owner, field_name: ni
434427
end
435428

436429
unless default_values_by_location.empty?
437-
kwargs[:default_value] = @default_value_merger.call(default_values_by_location, {
430+
kwargs[:default_value] = @formatter.merge_default_values(default_values_by_location, Formatter::Info.new(
438431
type_name: type_name,
439432
field_name: field_name,
440433
argument_name: argument_name,
441434
directive_name: directive_name,
442-
}.tap(&:compact!))
435+
))
443436
end
444437

445438
type = merge_value_types(type_name, value_types, argument_name: argument_name, field_name: field_name)
@@ -468,7 +461,7 @@ def build_merged_directives(type_name, members_by_location, owner, field_name: n
468461
end
469462

470463
directives_by_name_location.each do |directive_name, directives_by_location|
471-
kwarg_merger = @directive_kwarg_merger
464+
kwarg_formatter = @formatter
472465
directive_class = @schema_directives[directive_name]
473466
next unless directive_class
474467

@@ -491,19 +484,19 @@ def build_merged_directives(type_name, members_by_location, owner, field_name: n
491484

492485
if (profiles = kwarg_values_by_name_location["profiles"])
493486
@visibility_profiles.merge(profiles.each_value.reduce(&:|))
494-
kwarg_merger = VISIBILITY_PROFILES_MERGER
487+
kwarg_formatter = VISIBILITY_PROFILES_MERGER
495488
end
496489
end
497490

498491
kwargs = kwarg_values_by_name_location.each_with_object({}) do |(kwarg_name, kwarg_values_by_location), memo|
499-
memo[kwarg_name.to_sym] = kwarg_merger.call(kwarg_values_by_location, {
492+
memo[kwarg_name.to_sym] = kwarg_formatter.merge_kwargs(kwarg_values_by_location, Formatter::Info.new(
500493
type_name: type_name,
501494
field_name: field_name,
502495
argument_name: argument_name,
503496
enum_value: enum_value,
504497
directive_name: directive_name,
505498
kwarg_name: kwarg_name,
506-
}.tap(&:compact!))
499+
))
507500
end
508501

509502
owner.directive(directive_class, **kwargs)

test/graphql/stitching/composer/merge_arguments_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_merges_argument_descriptions
9090
b = %|input Test { """b""" arg:String } type Query { test("""b""" arg:Test):String }|
9191

9292
supergraph = compose_definitions({ "a" => a, "b" => b }, {
93-
formatter: JoinFormatter.new,
93+
formatter: TestFormatter.new,
9494
})
9595

9696
assert_equal "a/b", supergraph.schema.types["Test"].arguments["arg"].description
@@ -121,7 +121,7 @@ def test_merges_argument_directives
121121
|
122122

123123
supergraph = compose_definitions({ "a" => a, "b" => b }, {
124-
directive_kwarg_merger: ->(str_by_location, _info) { str_by_location.values.join("/") }
124+
formatter: TestFormatter.new,
125125
})
126126

127127
directive = supergraph.schema.types["Query"].fields["test"].arguments["arg"].directives.first
@@ -170,7 +170,7 @@ def test_merged_field_arguments_with_selected_default_value
170170
c = %|type Query { test(arg:Int = 2):String }|
171171

172172
supergraph = compose_definitions({ "a" => a, "b" => b, "c" => c }, {
173-
default_value_merger: ->(values_by_location, _info) { values_by_location.values.max }
173+
formatter: TestFormatter.new,
174174
})
175175
assert_equal 2, supergraph.schema.types["Query"].fields["test"].arguments["arg"].default_value
176176
end

test/graphql/stitching/composer/merge_directive_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_merges_directive_definitions
1919
|
2020

2121
supergraph = compose_definitions({ "a" => a, "b" => b }, {
22-
formatter: JoinFormatter.new,
22+
formatter: TestFormatter.new,
2323
})
2424

2525
directive_definition = supergraph.schema.directives["fizzbuzz"]
@@ -43,7 +43,7 @@ def test_combines_distinct_directives_assigned_to_an_element
4343
|
4444

4545
supergraph = compose_definitions({ "a" => a, "b" => b }, {
46-
directive_kwarg_merger: ->(str_by_location, _info) { str_by_location.values.join("/") }
46+
formatter: TestFormatter.new,
4747
})
4848

4949
directives = supergraph.schema.types["Test"].directives
@@ -67,7 +67,7 @@ def test_omits_stitching_directives_and_includes_supergraph_directives
6767
|
6868

6969
supergraph = compose_definitions({ "a" => a, "b" => b }, {
70-
directive_kwarg_merger: ->(str_by_location, _info) { str_by_location.values.join("/") }
70+
formatter: TestFormatter.new,
7171
})
7272

7373
assert !supergraph.schema.directives.key?("stitch")
@@ -92,7 +92,7 @@ def test_merges_camel_case_directive_values
9292
|
9393

9494
supergraph = compose_definitions({ "a" => a, "b" => b }, {
95-
directive_kwarg_merger: ->(str_by_location, _info) { str_by_location.values.join("/") }
95+
formatter: TestFormatter.new,
9696
})
9797

9898
directives = supergraph.schema.get_type("Test").directives

test/graphql/stitching/composer/merge_enum_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_merges_enum_and_value_descriptions
99
b = %|"""b""" enum Status { """b""" YES } type Query { status:Status }|
1010

1111
supergraph = compose_definitions({ "a" => a, "b" => b }, {
12-
formatter: JoinFormatter.new,
12+
formatter: TestFormatter.new,
1313
})
1414

1515
assert_equal "a/b", supergraph.schema.types["Status"].description
@@ -30,7 +30,7 @@ def test_merges_enum_and_value_directives
3030
|
3131

3232
supergraph = compose_definitions({ "a" => a, "b" => b }, {
33-
directive_kwarg_merger: ->(str_by_location, _info) { str_by_location.values.join("/") }
33+
formatter: TestFormatter.new,
3434
})
3535

3636
assert_equal "a/b", supergraph.schema.types["Status"].directives.first.arguments.keyword_arguments[:arg]

test/graphql/stitching/composer/merge_fields_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_merges_field_descriptions
99
b = %{type Test { """b""" field: String } type Query { test:Test }}
1010

1111
supergraph = compose_definitions({ "a" => a, "b" => b }, {
12-
formatter: JoinFormatter.new,
12+
formatter: TestFormatter.new,
1313
})
1414

1515
assert_equal "a/b", supergraph.schema.types["Test"].fields["field"].description
@@ -38,7 +38,7 @@ def test_merges_field_directives
3838
|
3939

4040
supergraph = compose_definitions({ "a" => a, "b" => b }, {
41-
directive_kwarg_merger: ->(str_by_location, _info) { str_by_location.values.join("/") }
41+
formatter: TestFormatter.new,
4242
})
4343

4444
assert_equal "a/b", supergraph.schema.types["Query"].fields["test"].directives.first.arguments.keyword_arguments[:arg]

test/graphql/stitching/composer/merge_input_object_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_merges_input_object_descriptions
99
b = %{"""b""" input Test { field:String } type Query { get(test:Test):String }}
1010

1111
info = compose_definitions({ "a" => a, "b" => b }, {
12-
formatter: JoinFormatter.new,
12+
formatter: TestFormatter.new,
1313
})
1414

1515
assert_equal "a/b", info.schema.types["Test"].description
@@ -29,7 +29,7 @@ def test_merges_input_object_and_field_directives
2929
|
3030

3131
supergraph = compose_definitions({ "a" => a, "b" => b }, {
32-
directive_kwarg_merger: ->(str_by_location, _info) { str_by_location.values.join("/") }
32+
formatter: TestFormatter.new,
3333
})
3434

3535
assert_equal "a/b", supergraph.schema.types["Test"].directives.first.arguments.keyword_arguments[:arg]

test/graphql/stitching/composer/merge_interface_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_merges_interface_descriptions
99
b = %{"""b""" interface Test { field: String } type Query { test:Test }}
1010

1111
supergraph = compose_definitions({ "a" => a, "b" => b }, {
12-
formatter: JoinFormatter.new,
12+
formatter: TestFormatter.new,
1313
})
1414

1515
assert_equal "a/b", supergraph.schema.types["Test"].description
@@ -29,7 +29,7 @@ def test_merges_interface_directives
2929
|
3030

3131
supergraph = compose_definitions({ "a" => a, "b" => b }, {
32-
directive_kwarg_merger: ->(str_by_location, _info) { str_by_location.values.join("/") }
32+
formatter: TestFormatter.new,
3333
})
3434

3535
assert_equal "a/b", supergraph.schema.types["Test"].directives.first.arguments.keyword_arguments[:arg]

test/graphql/stitching/composer/merge_object_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_merges_object_descriptions
99
b = %{"""b""" type Test { field: String } type Query { test:Test }}
1010

1111
supergraph = compose_definitions({ "a" => a, "b" => b }, {
12-
formatter: JoinFormatter.new,
12+
formatter: TestFormatter.new,
1313
})
1414

1515
assert_equal "a/b", supergraph.schema.types["Test"].description
@@ -29,7 +29,7 @@ def test_merges_object_directives
2929
|
3030

3131
supergraph = compose_definitions({ "a" => a, "b" => b }, {
32-
directive_kwarg_merger: ->(str_by_location, _info) { str_by_location.values.join("/") }
32+
formatter: TestFormatter.new,
3333
})
3434

3535
assert_equal "a/b", supergraph.schema.types["Test"].directives.first.arguments.keyword_arguments[:arg]

test/graphql/stitching/composer/merge_scalar_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_merges_scalar_descriptions
99
b = %{"""b""" scalar URL type Query { url:URL }}
1010

1111
info = compose_definitions({ "a" => a, "b" => b }, {
12-
formatter: JoinFormatter.new,
12+
formatter: TestFormatter.new,
1313
})
1414

1515
assert_equal "a/b", info.schema.get_type("URL").description
@@ -29,7 +29,7 @@ def test_merges_scalar_directives
2929
GRAPHQL
3030

3131
supergraph = compose_definitions({ "a" => a, "b" => b }, {
32-
directive_kwarg_merger: ->(str_by_location, _info) { str_by_location.values.join("/") }
32+
formatter: TestFormatter.new,
3333
})
3434

3535
assert_equal "a/b", supergraph.schema.get_type("Thing").directives.first.arguments.keyword_arguments[:arg]

test/graphql/stitching/composer/merge_union_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_merges_union_descriptions
1818
b = %{type B { b:Int } """b""" union Thing = B type Query { thing:Thing }}
1919

2020
info = compose_definitions({ "a" => a, "b" => b }, {
21-
formatter: JoinFormatter.new,
21+
formatter: TestFormatter.new,
2222
})
2323

2424
assert_equal "a/b", info.schema.get_type("Thing").description
@@ -40,7 +40,7 @@ def test_merges_union_directives
4040
GRAPHQL
4141

4242
supergraph = compose_definitions({ "a" => a, "b" => b }, {
43-
directive_kwarg_merger: ->(str_by_location, _info) { str_by_location.values.join("/") }
43+
formatter: TestFormatter.new,
4444
})
4545

4646
assert_equal "a/b", supergraph.schema.get_type("Thing").directives.first.arguments.keyword_arguments[:arg]

0 commit comments

Comments
 (0)