Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly hide definition directives in SDL #5175

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/graphql/language/document_from_schema_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,11 @@ def directives(member)
end

def definition_directives(member, directives_method)
dirs = if !member.respond_to?(directives_method) || member.directives.empty?
if !member.respond_to?(directives_method) || member.directives.empty?
EmptyObjects::EMPTY_ARRAY
else
member.public_send(directives_method).map do |dir|
visible_directives = member.public_send(directives_method).select { |dir| @types.directive_exists?(dir.graphql_name) }
visible_directives.map! do |dir|
args = []
dir.arguments.argument_values.each_value do |arg_value| # rubocop:disable Development/ContextIsPassedCop -- directive instance method
arg_defn = arg_value.definition
Expand All @@ -373,9 +374,9 @@ def definition_directives(member, directives_method)
arguments: args
)
end
end

dirs
visible_directives
end
end

attr_reader :schema, :always_include_schema,
Expand Down
15 changes: 12 additions & 3 deletions spec/graphql/schema/printer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ module Node
field :id, ID, null: false
end

class HiddenDirective < GraphQL::Schema::Directive
def self.visible?(ctx); false; end
locations(GraphQL::Schema::Directive::ENUM_VALUE)
end

class Choice < GraphQL::Schema::Enum
value "FOO", value: :foo
value "BAR", value: :bar
value "BAR", value: :bar, directives: { HiddenDirective => {} }
value "BAZ", deprecation_reason: <<-REASON
Use "BAR" instead.

Expand Down Expand Up @@ -120,6 +125,10 @@ class Subscription < GraphQL::Schema::Object
mutation(Mutation)
subscription(Subscription)
extra_types [MediaRating]

if !use_visibility_profile?
use GraphQL::Schema::Warden
end
end

let(:schema) { PrinterTestSchema }
Expand Down Expand Up @@ -689,7 +698,7 @@ def self.visible?(member, ctx)
case member
when Module
if !member.respond_to?(:kind)
true
super
else
case member.kind.name
when "SCALAR"
Expand Down Expand Up @@ -815,7 +824,7 @@ def self.visible?(member, ctx)
custom_filter_schema = Class.new(schema) do
use GraphQL::Schema::Warden if ADD_WARDEN
def self.visible?(member, ctx)
!(ctx[:names].include?(member.graphql_name) || (member.respond_to?(:deprecation_reason) && member.deprecation_reason))
super && (!(ctx[:names].include?(member.graphql_name) || (member.respond_to?(:deprecation_reason) && member.deprecation_reason)))
end
end

Expand Down
Loading