Class: GraphQL::Api::Resolvers::ModelCreateMutation
- Inherits:
-
Object
- Object
- GraphQL::Api::Resolvers::ModelCreateMutation
- Defined in:
- lib/graphql/api/resolvers/model_create_mutation.rb
Instance Method Summary collapse
- #call(obj, args, ctx) ⇒ Object
-
#initialize(model, policy = nil) ⇒ ModelCreateMutation
constructor
A new instance of ModelCreateMutation.
- #key ⇒ Object
Constructor Details
#initialize(model, policy = nil) ⇒ ModelCreateMutation
Returns a new instance of ModelCreateMutation.
5 6 7 8 |
# File 'lib/graphql/api/resolvers/model_create_mutation.rb', line 5 def initialize(model, policy=nil) @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 |
# File 'lib/graphql/api/resolvers/model_create_mutation.rb', line 10 def call(obj, args, ctx) if @policy_class policy = @policy_class.new(ctx, nil) return policy. unless policy.create? end item = @model.create!(args.to_h) {key => item} end |
#key ⇒ Object
20 21 22 |
# File 'lib/graphql/api/resolvers/model_create_mutation.rb', line 20 def key @model.name.underscore.to_sym end |