Class: GraphQL::Api::Resolvers::Field
- Inherits:
-
Object
- Object
- GraphQL::Api::Resolvers::Field
- Defined in:
- lib/graphql/api/resolvers/field.rb
Instance Method Summary collapse
- #call(obj, args, ctx) ⇒ Object
-
#initialize(model, name) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(model, name) ⇒ Field
Returns a new instance of Field.
5 6 7 8 9 |
# File 'lib/graphql/api/resolvers/field.rb', line 5 def initialize(model, name) @model = model @name = name @policy_class = "#{model.name}Policy".safe_constantize end |
Instance Method Details
#call(obj, args, ctx) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/graphql/api/resolvers/field.rb', line 11 def call(obj, args, ctx) if @policy_class policy = @policy_class.new(ctx, obj) return policy. unless policy.read? if policy.respond_to?("access_#{@name}?") return policy.(@name) unless policy.send("access_#{@name}?") end obj.send(@name) elsif obj.respond_to?("access_#{@name}?") obj.send(@name) if obj.send("access_#{@name}?", ctx) else obj.send(@name) end end |