Sha256: 41e94af1066cc20c03902ebe2efad9cb40bf954bc59377182f6f208175e1aeed

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module GraphqlRails
  # contains configuration options related with inputs
  module InputConfigurable
    def permit(*args)
      args.each do |arg|
        if arg.is_a? Hash
          arg.each { |attribute, type| permit_input(attribute, type: type) }
        else
          permit_input(arg)
        end
      end
      self
    end

    def permit_input(name, **input_options)
      field_name = name.to_s.remove(/!\Z/)

      attributes[field_name] = build_input_attribute(name.to_s, **input_options)
      self
    end

    def paginated(pagination_options = {})
      pagination_options = {} if pagination_options == true
      pagination_options = nil if pagination_options == false

      @pagination_options = pagination_options
      self
    end

    def paginated?
      !pagination_options.nil?
    end

    def pagination_options
      @pagination_options
    end

    def input_attribute_options
      @input_attribute_options || {}
    end

    def build_input_attribute(name, options: {}, **other_options)
      input_options = input_attribute_options.merge(options)
      Attributes::InputAttribute.new(name.to_s, config: self).with(options: input_options, **other_options)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
graphql_rails-3.0.0 lib/graphql_rails/input_configurable.rb
graphql_rails-2.4.0 lib/graphql_rails/input_configurable.rb
graphql_rails-2.3.0 lib/graphql_rails/input_configurable.rb
graphql_rails-2.2.0 lib/graphql_rails/input_configurable.rb