Sha256: 905a6a46e91e81052d7832d1eda9abf287e74a463a5b8469812407c15d7b6796

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 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
      permit(:before, :after, first: :int, last: :int)
    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)
      Attributes::InputAttribute.new(
        name.to_s,
        options: input_attribute_options.merge(options),
        **other_options
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql_rails-1.2.6 lib/graphql_rails/input_configurable.rb