@@ -23,6 +23,9 @@ class Composer
2323
2424 # @api private
2525 BASIC_VALUE_MERGER = -> ( values_by_location , _info ) { values_by_location . values . find { !_1 . nil? } }
26+
27+ # @api private
28+ VISIBILITY_PROFILES_MERGER = -> ( values_by_location , _info ) { values_by_location . values . reduce ( :& ) }
2629
2730 # @api private
2831 BASIC_ROOT_FIELD_LOCATION_SELECTOR = -> ( locations , _info ) { locations . last }
@@ -237,7 +240,7 @@ def build_scalar_type(type_name, types_by_location)
237240
238241 builder = self
239242
240- Class . new ( GraphQL ::Schema :: Scalar ) do
243+ Class . new ( GraphQL ::Stitching :: Supergraph :: BaseScalar ) do
241244 graphql_name ( type_name )
242245 description ( builder . merge_descriptions ( type_name , types_by_location ) )
243246 builder . build_merged_directives ( type_name , types_by_location , self )
@@ -264,7 +267,7 @@ def build_enum_type(type_name, types_by_location, enum_usage)
264267 end
265268 end
266269
267- Class . new ( GraphQL ::Schema :: Enum ) do
270+ Class . new ( GraphQL ::Stitching :: Supergraph :: BaseEnum ) do
268271 graphql_name ( type_name )
269272 description ( builder . merge_descriptions ( type_name , types_by_location ) )
270273 builder . build_merged_directives ( type_name , types_by_location , self )
@@ -286,7 +289,7 @@ def build_enum_type(type_name, types_by_location, enum_usage)
286289 def build_object_type ( type_name , types_by_location )
287290 builder = self
288291
289- Class . new ( GraphQL ::Schema :: Object ) do
292+ Class . new ( GraphQL ::Stitching :: Supergraph :: BaseObject ) do
290293 graphql_name ( type_name )
291294 description ( builder . merge_descriptions ( type_name , types_by_location ) )
292295
@@ -306,7 +309,7 @@ def build_interface_type(type_name, types_by_location)
306309 builder = self
307310
308311 Module . new do
309- include GraphQL ::Schema :: Interface
312+ include GraphQL ::Stitching :: Supergraph :: BaseInterface
310313 graphql_name ( type_name )
311314 description ( builder . merge_descriptions ( type_name , types_by_location ) )
312315
@@ -325,7 +328,7 @@ def build_interface_type(type_name, types_by_location)
325328 def build_union_type ( type_name , types_by_location )
326329 builder = self
327330
328- Class . new ( GraphQL ::Schema :: Union ) do
331+ Class . new ( GraphQL ::Stitching :: Supergraph :: BaseUnion ) do
329332 graphql_name ( type_name )
330333 description ( builder . merge_descriptions ( type_name , types_by_location ) )
331334
@@ -340,7 +343,7 @@ def build_union_type(type_name, types_by_location)
340343 def build_input_object_type ( type_name , types_by_location )
341344 builder = self
342345
343- Class . new ( GraphQL ::Schema :: InputObject ) do
346+ Class . new ( GraphQL ::Stitching :: Supergraph :: BaseInputObject ) do
344347 graphql_name ( type_name )
345348 description ( builder . merge_descriptions ( type_name , types_by_location ) )
346349 builder . build_merged_arguments ( type_name , types_by_location , self )
@@ -451,12 +454,21 @@ def build_merged_directives(type_name, members_by_location, owner, field_name: n
451454 end
452455
453456 directives_by_name_location . each do |directive_name , directives_by_location |
457+ kwarg_merger = @directive_kwarg_merger
454458 directive_class = @schema_directives [ directive_name ]
455459 next unless directive_class
456460
457461 # handled by deprecation_reason merger...
458462 next if directive_class . graphql_name == "deprecated"
459463
464+ if directive_class . graphql_name == GraphQL ::Stitching . visibility_directive
465+ unless GraphQL ::Stitching . supports_visibility?
466+ raise CompositionError , "Using `@#{ GraphQL ::Stitching . visibility_directive } ` directive " \
467+ "for schema visibility controls requires GraphQL Ruby v2.4.15 or later."
468+ end
469+ kwarg_merger = VISIBILITY_PROFILES_MERGER
470+ end
471+
460472 kwarg_values_by_name_location = directives_by_location . each_with_object ( { } ) do |( location , directive ) , memo |
461473 directive . arguments . keyword_arguments . each do |key , value |
462474 key = key . to_s
@@ -468,7 +480,7 @@ def build_merged_directives(type_name, members_by_location, owner, field_name: n
468480 end
469481
470482 kwargs = kwarg_values_by_name_location . each_with_object ( { } ) do |( kwarg_name , kwarg_values_by_location ) , memo |
471- memo [ kwarg_name . to_sym ] = @directive_kwarg_merger . call ( kwarg_values_by_location , {
483+ memo [ kwarg_name . to_sym ] = kwarg_merger . call ( kwarg_values_by_location , {
472484 type_name : type_name ,
473485 field_name : field_name ,
474486 argument_name : argument_name ,
0 commit comments