Sha256: 6a6e385d56cebf0851f699a4b4a9a245f756f0e59214488d1913a1e07c4ccfb9

Contents?: true

Size: 876 Bytes

Versions: 5

Compression:

Stored size: 876 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  module Define
    # Turn argument configs into a {GraphQL::Argument}.
    module AssignArgument
      def self.call(target, name, type = nil, description = nil, **rest, &block)
        argument = if block_given?
          GraphQL::Argument.define(&block)
        else
          GraphQL::Argument.new
        end

        unsupported_keys = rest.keys - [:default_value]
        if unsupported_keys.any?
          raise ArgumentError.new("unknown keyword#{unsupported_keys.length > 1 ? 's' : ''}: #{unsupported_keys.join(', ')}")
        end

        argument.name = name.to_s
        type && argument.type = type
        description && argument.description = description
        rest.key?(:default_value) && argument.default_value = rest[:default_value]

        target.arguments[name.to_s] = argument
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
graphql-1.4.3 lib/graphql/define/assign_argument.rb
graphql-1.4.2 lib/graphql/define/assign_argument.rb
graphql-1.4.1 lib/graphql/define/assign_argument.rb
graphql-1.4.0 lib/graphql/define/assign_argument.rb
graphql-1.3.0 lib/graphql/define/assign_argument.rb