I'm trying to make it so that certain directives of a schema are only present in certain contexts (e.g., federation directives only included in federated contexts). From playing around with the .visible? hook, it seems like a directive that isn't visible has its definition removed, but the usage of the directive still exists. For example, the following script:
require 'bundler'
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'graphql', '2.4.4'
end
class MyDirective < GraphQL::Schema::Directive
locations OBJECT
def self.visible?(context)
context.fetch(:show_directives)
end
end
class Query < GraphQL::Schema::Object
directive MyDirective
field :my_string, String, null: false
end
class MySchema < GraphQL::Schema
use GraphQL::Schema::Visibility
query Query
end
puts "# show_directives: true"
puts MySchema.to_definition(context: { show_directives: true })
puts "\n# show_directives: false"
puts MySchema.to_definition(context: { show_directives: false })
Produces the following output:
# show_directives: true
directive @myDirective on OBJECT
type Query @myDirective {
myString: String!
}
# show_directives: false
type Query @myDirective {
myString: String!
}
The output I would expect is:
# show_directives: false
type Query {
myString: String!
}
Is that the expected behavior of the .visible? hook on directives?
Describe the bug
I'm trying to make it so that certain directives of a schema are only present in certain contexts (e.g., federation directives only included in federated contexts). From playing around with the
.visible?
hook, it seems like a directive that isn't visible has its definition removed, but the usage of the directive still exists. For example, the following script:Produces the following output:
The output I would expect is:
Is that the expected behavior of the
.visible?
hook on directives?