Class: HQ::GraphQL::Field
- Inherits:
-
GraphQL::Schema::Field
- Object
- GraphQL::Schema::Field
- HQ::GraphQL::Field
- Defined in:
- lib/hq/graphql/field.rb
Instance Attribute Summary collapse
-
#authorize ⇒ Object
readonly
Returns the value of attribute authorize.
-
#authorize_action ⇒ Object
readonly
Returns the value of attribute authorize_action.
Instance Method Summary collapse
- #authorized?(object, _args, ctx) ⇒ Boolean
-
#initialize(*args, authorize_action: :read, authorize: nil, klass: nil, **options, &block) ⇒ Field
constructor
A new instance of Field.
- #klass ⇒ Object
- #scope(&block) ⇒ Object
Constructor Details
#initialize(*args, authorize_action: :read, authorize: nil, klass: nil, **options, &block) ⇒ Field
Returns a new instance of Field.
8 9 10 11 12 13 |
# File 'lib/hq/graphql/field.rb', line 8 def initialize(*args, authorize_action: :read, authorize: nil, klass: nil, **, &block) super(*args, **, &block) @authorize_action = @authorize = @klass_or_string = klass end |
Instance Attribute Details
#authorize ⇒ Object (readonly)
Returns the value of attribute authorize.
6 7 8 |
# File 'lib/hq/graphql/field.rb', line 6 def @authorize end |
#authorize_action ⇒ Object (readonly)
Returns the value of attribute authorize_action.
6 7 8 |
# File 'lib/hq/graphql/field.rb', line 6 def @authorize_action end |
Instance Method Details
#authorized?(object, _args, ctx) ⇒ Boolean
23 24 25 26 27 |
# File 'lib/hq/graphql/field.rb', line 23 def (object, _args, ctx) super && (! || .call(object, ctx)) && ::HQ::GraphQL.(, self, object, ctx) end |
#klass ⇒ Object
29 30 31 |
# File 'lib/hq/graphql/field.rb', line 29 def klass @klass ||= @klass_or_string.is_a?(String) ? @klass_or_string.constantize : @klass_or_string end |
#scope(&block) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/hq/graphql/field.rb', line 15 def scope(&block) if block @scope = block else @scope end end |