Class: GraphQL::Api::Resolvers::ModelUpdateMutation
- Inherits:
-
Object
- Object
- GraphQL::Api::Resolvers::ModelUpdateMutation
- Defined in:
- lib/graphql/api/resolvers/model_update_mutation.rb
Instance Method Summary collapse
- #call(obj, args, ctx) ⇒ Object
-
#initialize(model) ⇒ ModelUpdateMutation
constructor
A new instance of ModelUpdateMutation.
- #key ⇒ Object
Constructor Details
#initialize(model) ⇒ ModelUpdateMutation
Returns a new instance of ModelUpdateMutation.
5 6 7 8 |
# File 'lib/graphql/api/resolvers/model_update_mutation.rb', line 5 def initialize(model) @model = model @policy_class = "#{model.name}Policy".safe_constantize end |
Instance Method Details
#call(obj, args, ctx) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/graphql/api/resolvers/model_update_mutation.rb', line 10 def call(obj, args, ctx) item = @model.find(args[:id]) if @policy_class policy = @policy_class.new(ctx, item) return policy. unless policy.destroy? end item.update!(args.to_h) {key => item} end |
#key ⇒ Object
22 23 24 |
# File 'lib/graphql/api/resolvers/model_update_mutation.rb', line 22 def key @model.name.underscore.to_sym end |