Skip to content

Commit d2f5780

Browse files
committed
setup formatter.
1 parent 2152021 commit d2f5780

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

lib/graphql/stitching/composer.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def perform(locations_input)
174174
select_root_field_locations(schema)
175175
expand_abstract_resolvers(schema, schemas)
176176
apply_supergraph_directives(schema, @resolver_map, @field_map)
177-
apply_authorization_directives(schema, @authorizations_by_type_and_field)
177+
apply_authorization_directives(schema)
178178

179179
if (visibility_def = schema.directives[GraphQL::Stitching.visibility_directive])
180180
visibility_def.get_argument("profiles").default_value(@visibility_profiles.to_a.sort)
@@ -536,6 +536,7 @@ def merge_descriptions(type_name, members_by_location, field_name: nil, argument
536536
@formatter.merge_descriptions(strings_by_location, Formatter::Info.new(
537537
type_name: type_name,
538538
field_name: field_name,
539+
field_scopes: field_name ? @authorizations_by_type_and_field.dig(type_name, field_name) : nil,
539540
argument_name: argument_name,
540541
enum_value: enum_value,
541542
))
@@ -761,11 +762,11 @@ def apply_supergraph_directives(schema, resolvers_by_type_name, locations_by_typ
761762
schema_directives.each_value { |directive_class| schema.directive(directive_class) }
762763
end
763764

764-
def apply_authorization_directives(schema, authorizations_by_type_and_field)
765-
return if authorizations_by_type_and_field.empty?
765+
def apply_authorization_directives(schema)
766+
return if @authorizations_by_type_and_field.empty?
766767

767768
schema.types.each_value do |type|
768-
authorizations_by_field = authorizations_by_type_and_field[type.graphql_name]
769+
authorizations_by_field = @authorizations_by_type_and_field[type.graphql_name]
769770
next if authorizations_by_field.nil? || !type.kind.fields?
770771

771772
type.fields.each_value do |field|

lib/graphql/stitching/composer/authorization.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@
33
module GraphQL::Stitching
44
class Composer
55
module Authorization
6+
class << self
7+
def print_scopes(or_scopes)
8+
or_scopes.map do |and_scopes|
9+
and_scopes = and_scopes.map { "`#{_1}`" }
10+
if and_scopes.length > 2
11+
"#{and_scopes[0..-1].join(",")}, and #{and_scopes.last}"
12+
else
13+
and_scopes.join(" and ")
14+
end
15+
end
16+
17+
or_scopes.join("; or ")
18+
end
19+
20+
def print_description(scopes)
21+
"Required authorization scopes: #{print_scopes(scopes)}."
22+
end
23+
end
24+
625
private
726

827
def merge_authorization_scopes(*scopes)

test/graphql/stitching/planner/plan_authorizations_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def test_selects_unmerged_object_fields_with_authorization
260260
variables: {},
261261
path: [],
262262
}],
263-
claims: ["orders", "customers"],
263+
claims: ["customers", "orders"],
264264
errors: [],
265265
}
266266

0 commit comments

Comments
 (0)