Class: GraphQL::Schema::Visibility
- Inherits:
-
Object
- Object
- GraphQL::Schema::Visibility
- Defined in:
- lib/graphql/schema/visibility.rb,
lib/graphql/schema/visibility/profile.rb,
lib/graphql/schema/visibility/migration.rb
Overview
Use this plugin to make some parts of your schema hidden from some viewers.
Defined Under Namespace
Instance Attribute Summary collapse
-
#cached_profiles ⇒ Object
readonly
Returns the value of attribute cached_profiles.
Class Method Summary collapse
Instance Method Summary collapse
-
#dup_for(other_schema) ⇒ Visibility
private
Make another Visibility for
schema
based on this one. -
#initialize(schema, dynamic:, preload:, profiles:, migration_errors:) ⇒ Visibility
constructor
A new instance of Visibility.
-
#migration_errors? ⇒ Boolean
-
#profile_for(context, visibility_profile) ⇒ Object
Constructor Details
#initialize(schema, dynamic:, preload:, profiles:, migration_errors:) ⇒ Visibility
Returns a new instance of Visibility.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/graphql/schema/visibility.rb', line 18 def initialize(schema, dynamic:, preload:, profiles:, migration_errors:) @schema = schema schema.use_visibility_profile = true if migration_errors schema.visibility_profile_class = Migration end @profiles = profiles @cached_profiles = {} @dynamic = dynamic @migration_errors = migration_errors if preload profiles.each do |profile_name, example_ctx| example_ctx[:visibility_profile] = profile_name prof = profile_for(example_ctx, profile_name) prof.all_types # force loading end end end |
Instance Attribute Details
#cached_profiles ⇒ Object (readonly)
Returns the value of attribute cached_profiles.
54 55 56 |
# File 'lib/graphql/schema/visibility.rb', line 54 def cached_profiles @cached_profiles end |
Class Method Details
.use(schema, dynamic: false, profiles: EmptyObjects::EMPTY_HASH, preload: (Rails) ? Rails.env.production? : nil), migration_errors: false) ⇒ Object
14 15 16 |
# File 'lib/graphql/schema/visibility.rb', line 14 def self.use(schema, dynamic: false, profiles: EmptyObjects::EMPTY_HASH, preload: (defined?(Rails) ? Rails.env.production? : nil), migration_errors: false) schema.visibility = self.new(schema, dynamic: dynamic, preload: preload, profiles: profiles, migration_errors: migration_errors) end |
Instance Method Details
#dup_for(other_schema) ⇒ Visibility
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Make another Visibility for schema
based on this one
40 41 42 43 44 45 46 47 48 |
# File 'lib/graphql/schema/visibility.rb', line 40 def dup_for(other_schema) self.class.new( other_schema, dynamic: @dynamic, preload: @preload, profiles: @profiles, migration_errors: @migration_errors ) end |
#migration_errors? ⇒ Boolean
50 51 52 |
# File 'lib/graphql/schema/visibility.rb', line 50 def migration_errors? @migration_errors end |
#profile_for(context, visibility_profile) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/graphql/schema/visibility.rb', line 56 def profile_for(context, visibility_profile) if @profiles.any? if visibility_profile.nil? if @dynamic @schema.visibility_profile_class.new(context: context, schema: @schema) elsif @profiles.any? raise ArgumentError, "#{@schema} expects a visibility profile, but `visibility_profile:` wasn't passed. Provide a `visibility_profile:` value or add `dynamic: true` to your visibility configuration." end elsif !@profiles.include?(visibility_profile) raise ArgumentError, "`#{visibility_profile.inspect}` isn't allowed for `visibility_profile:` (must be one of #{@profiles.keys.map(&:inspect).join(", ")}). Or, add `#{visibility_profile.inspect}` to the list of profiles in the schema definition." else @cached_profiles[visibility_profile] ||= @schema.visibility_profile_class.new(name: visibility_profile, context: context, schema: @schema) end else @schema.visibility_profile_class.new(context: context, schema: @schema) end end |