Class: GraphQL::Schema::Warden Private
- Inherits:
-
Object
- Object
- GraphQL::Schema::Warden
- Defined in:
- lib/graphql/schema/warden.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Restrict access to a GraphQL::Schema with a user-defined mask.
The mask is object that responds to #visible?(schema_member)
.
When validating and executing a query, all access to schema members should go through a warden. If you access the schema directly, you may show a client something that it shouldn't be allowed to see.
Masks can be provided in #execute (or Query#initialize) with the mask:
keyword.
Instance Method Summary collapse
-
#arguments(argument_owner) ⇒ Array<GraphQL::Argument>
private
Visible arguments on
argument_owner
. - #directives ⇒ Object private
-
#enum_values(enum_defn) ⇒ Array<GraphQL::EnumType::EnumValue>
private
Visible members of
enum_defn
. -
#fields(type_defn) ⇒ Array<GraphQL::Field>
private
Fields on
type_defn
. -
#get_field(parent_type, field_name) ⇒ GraphQL::Field?
private
The field named
field_name
onparent_type
, if it exists. -
#get_type(type_name) ⇒ GraphQL::BaseType?
private
The type named
type_name
, if it exists (elsenil
). -
#initialize(mask, context:, schema:) ⇒ Warden
constructor
private
A new instance of Warden.
-
#interfaces(obj_type) ⇒ Array<GraphQL::InterfaceType>
private
Visible interfaces implemented by
obj_type
. -
#possible_types(type_defn) ⇒ Array<GraphQL::BaseType>
private
The types which may be member of
type_defn
. - #root_type_for_operation(op_name) ⇒ Object private
-
#types ⇒ Array<GraphQL::BaseType>
private
Visible types in the schema.
Constructor Details
#initialize(mask, context:, schema:) ⇒ Warden
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.
Returns a new instance of Warden.
45 46 47 48 |
# File 'lib/graphql/schema/warden.rb', line 45 def initialize(mask, context:, schema:) @schema = schema @visibility_cache = read_through { |m| !mask.call(m, context) } end |
Instance Method Details
#arguments(argument_owner) ⇒ Array<GraphQL::Argument>
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.
Returns Visible arguments on argument_owner
.
101 102 103 104 |
# File 'lib/graphql/schema/warden.rb', line 101 def arguments(argument_owner) @visible_arguments ||= read_through { |o| o.arguments.each_value.select { |a| visible_field?(a) } } @visible_arguments[argument_owner] end |
#directives ⇒ Object
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.
118 119 120 |
# File 'lib/graphql/schema/warden.rb', line 118 def directives @schema.directives.each_value.select { |d| visible?(d) } end |
#enum_values(enum_defn) ⇒ Array<GraphQL::EnumType::EnumValue>
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.
Returns Visible members of enum_defn
.
107 108 109 110 |
# File 'lib/graphql/schema/warden.rb', line 107 def enum_values(enum_defn) @visible_enum_values ||= read_through { |e| e.values.each_value.select { |enum_value_defn| visible?(enum_value_defn) } } @visible_enum_values[enum_defn] end |
#fields(type_defn) ⇒ Array<GraphQL::Field>
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.
Returns Fields on type_defn
.
94 95 96 97 |
# File 'lib/graphql/schema/warden.rb', line 94 def fields(type_defn) @visible_fields ||= read_through { |t| @schema.get_fields(t).each_value.select { |f| visible_field?(f) } } @visible_fields[type_defn] end |
#get_field(parent_type, field_name) ⇒ GraphQL::Field?
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.
Returns The field named field_name
on parent_type
, if it exists.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/graphql/schema/warden.rb', line 70 def get_field(parent_type, field_name) @visible_parent_fields ||= read_through do |type| read_through do |f_name| field_defn = @schema.get_field(type, f_name) if field_defn && visible_field?(field_defn) field_defn else nil end end end @visible_parent_fields[parent_type][field_name] end |
#get_type(type_name) ⇒ GraphQL::BaseType?
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.
Returns The type named type_name
, if it exists (else nil
).
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/graphql/schema/warden.rb', line 56 def get_type(type_name) @visible_types ||= read_through do |name| type_defn = @schema.types.fetch(name, nil) if type_defn && visible?(type_defn) type_defn else nil end end @visible_types[type_name] end |
#interfaces(obj_type) ⇒ Array<GraphQL::InterfaceType>
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.
Returns Visible interfaces implemented by obj_type
.
113 114 115 116 |
# File 'lib/graphql/schema/warden.rb', line 113 def interfaces(obj_type) @visible_interfaces ||= read_through { |t| t.interfaces.select { |i| visible?(i) } } @visible_interfaces[obj_type] end |
#possible_types(type_defn) ⇒ Array<GraphQL::BaseType>
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.
Returns The types which may be member of type_defn
.
87 88 89 90 |
# File 'lib/graphql/schema/warden.rb', line 87 def possible_types(type_defn) @visible_possible_types ||= read_through { |type_defn| @schema.possible_types(type_defn).select { |t| visible?(t) } } @visible_possible_types[type_defn] end |
#root_type_for_operation(op_name) ⇒ Object
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.
122 123 124 125 126 127 128 129 |
# File 'lib/graphql/schema/warden.rb', line 122 def root_type_for_operation(op_name) root_type = @schema.root_type_for_operation(op_name) if root_type && visible?(root_type) root_type else nil end end |
#types ⇒ Array<GraphQL::BaseType>
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.
Returns Visible types in the schema.
51 52 53 |
# File 'lib/graphql/schema/warden.rb', line 51 def types @types ||= @schema.types.each_value.select { |t| visible?(t) } end |