Sha256: 3d5d77f5d9374dc1756d152bf2d716f0f73cf1a71d7a6d6a24d2f1d49aace5c0

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'active_support/core_ext/string/filters'
require 'graphql_rails/attribute'

module GraphqlRails
  class Controller
    # stores all graphql_rails contoller specific config
    class ActionConfiguration
      attr_reader :attributes, :return_type

      def initialize
        @attributes = {}
        @can_return_nil = false
      end

      def permit(*no_type_attributes, **typed_attributes)
        no_type_attributes.each { |attribute| permit_attribute(attribute) }
        typed_attributes.each { |attribute, type| permit_attribute(attribute, type) }
        self
      end

      def can_return_nil
        @can_return_nil = true
        self
      end

      def returns(new_return_type)
        @return_type = new_return_type
        self
      end

      def can_return_nil?
        @can_return_nil
      end

      private

      def permit_attribute(name, type = nil)
        field_name = name.to_s.remove(/!\Z/)
        attributes[field_name] = Attribute.new(field_name, type)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
graphql_rails-0.2.2 lib/graphql_rails/controller/action_configuration.rb
graphql_rails-0.2.1 lib/graphql_rails/controller/action_configuration.rb
graphql_rails-0.2.0 lib/graphql_rails/controller/action_configuration.rb