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, ctx) ⇒ Boolean
-
#initialize(*args, authorize_action: :read, authorize: nil, klass: nil, **options, &block) ⇒ Field
constructor
A new instance of Field.
- #klass ⇒ Object
- #resolve_field(object, args, ctx) ⇒ 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) = = @class_name = 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 end |
#authorize_action ⇒ Object (readonly)
Returns the value of attribute authorize_action.
6 7 8 |
# File 'lib/hq/graphql/field.rb', line 6 def end |
Instance Method Details
#authorized?(object, ctx) ⇒ Boolean
15 16 17 18 19 |
# File 'lib/hq/graphql/field.rb', line 15 def (object, ctx) super && (! || .call(object, ctx)) && ::HQ::GraphQL.(, self, object, ctx) end |
#klass ⇒ Object
48 49 50 |
# File 'lib/hq/graphql/field.rb', line 48 def klass @klass ||= @class_name&.constantize end |
#resolve_field(object, args, ctx) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hq/graphql/field.rb', line 21 def resolve_field(object, args, ctx) if klass.present? && !!::GraphQL::Batch::Executor.current && object.object loader = if ::HQ::GraphQL.use_experimental_associations? limit = args[:limit] offset = args[:offset] sort_by = args[:sortBy] sort_order = args[:sortOrder] PaginatedAssociationLoader.for( klass, original_name, limit: limit, offset: offset, sort_by: sort_by, sort_order: sort_order ) else AssociationLoader.for(klass, original_name) end loader.load(object.object) else super end end |