-
|
I'm using visibility to hide portions of the schema. I've added If I understand the documentation correctly, this is working as intended, and is called out at the bottom of the guide on Visibility:
As suggested, I've been able to hide Union fields where all possible types are hidden using something like this: class BaseUnion < GraphQL::Schema::Union
def self.visible?(context)
super && possible_types.any? do |type|
type.visible_apps.include?(context[:visibility_profile])
end
end
endHowever, I'm not sure how to accomplish the same goal with an Interface. I was looking at Here's a rough example to detail the setup, and I am using version class QueryType < GraphQL::Schema::Object
field :post, resolver: Resolvers::Post
end
module Resolvers
class Post < BaseResolver
type Types::Post, null: true
def resolve; end
end
end
module Types
module BaseInterface
include GraphQL::Schema::Interface
definition_methods do
def visible?(context)
# return true if any of the Interface implementations are visible; else false
super
end
end
end
end
module Types
module Post
include Types::BaseInterface
field :foo, String
end
end
module Types
class Image < Types::BaseObject
implements Types::Post
end
end
module Types
class Text < Types::BaseObject
implements Types::Post
end
endAm I understanding Union and Interface Visibility correctly? And if so, how can I check if all of the Interface implementations are visible to hide the Interface itself from the Schema? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hey, yes, it sounds to me like you understand it correctly. The thing about an interface's Instead of referencing other GraphQL types inside (For background, interfaces don't store lists of their implementers because it would force them to all be eager-loaded in development -- but GraphQL-Ruby supports lazy-loading types as they're necessary, so that would be "bug".) |
Beta Was this translation helpful? Give feedback.
Hey, yes, it sounds to me like you understand it correctly.
The thing about an interface's
interface_type_membershipsis that it would contain other interfaces which this interface implements, not the objects that implement this interface.Instead of referencing other GraphQL types inside
.visible?, could you call the same code that those object types call in their.visible?methods? For example, ifTypes::Textcheckscan_see_text?andTypes::Imagecheckscan_see_images?, thenTypes::Postcould checkcan_see_text? || can_see_images?.(For background, interfaces don't store lists of their implementers because it would force them to all be eager-loaded in development -- but GraphQL-Ruby sup…