Sha256: 9add82ce0018c96b523bd8eab0b8c45f77efe033cfff02dbc05671434a5d12ec
Contents?: true
Size: 1.54 KB
Versions: 3
Compression:
Stored size: 1.54 KB
Contents
# frozen_string_literal: true module Rails # :nodoc: module GraphQL # :nodoc: # = GraphQL Output Field # # This is an extension of a normal output field, which just add extra # validation and ensurance that the +perform+ step can be executed class Field::MutationField < Field::OutputField redefine_singleton_method(:mutation?) { true } module Proxied # :nodoc: all def performer super || field.performer end end # Add a block or a callable method that is executed before the resolver # but after all the before resolve def perform(*args, **xargs, &block) @performer = Callback.new(self, :perform, *args, **xargs, &block) end # Get the performer that can be already defined or used through the # +method_name+ if that is callable def performer @performer ||= callable?(:"#{method_name}!") \ ? Callback.new(self, :perform, :"#{method_name}!") \ : false end # Ensures that the performer is defined def validate!(*) super if defined? super raise ValidationError, <<~MSG.squish unless performer.present? The "#{gql_name}" mutation field must have a perform action through a given block or a method named #{method_name} on #{owner.class.name}. MSG end protected def proxied # :nodoc: super if defined? super extend Field::MutationField::Proxied end end Field::ScopedConfig.delegate :perform, to: :field end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rails-graphql-0.1.3 | lib/rails/graphql/field/mutation_field.rb |
rails-graphql-0.1.2 | lib/rails/graphql/field/mutation_field.rb |
rails-graphql-0.1.1 | lib/rails/graphql/field/mutation_field.rb |