Sha256: 2fc1502430a5486576d04f7db5eef9c8eb8a00a69784ad3d11d817249d840b9c

Contents?: true

Size: 682 Bytes

Versions: 2

Compression:

Stored size: 682 Bytes

Contents

# Creates a plain hash out of arguments, looking up variables if necessary
class GraphQL::Query::Arguments
  attr_reader :to_h
  def initialize(ast_arguments, variables)
    @to_h = ast_arguments.reduce({}) do |memo, arg|
      value = reduce_value(arg.value, variables)
      memo[arg.name] = value
      memo
    end
  end

  private

  def reduce_value(value, variables)
    if value.is_a?(GraphQL::Nodes::VariableIdentifier)
      value = variables[value.name]
    elsif value.is_a?(GraphQL::Nodes::Enum)
      value = value.name
    elsif value.is_a?(GraphQL::Nodes::InputObject)
      value = self.class.new(value.pairs, variables).to_h
    else
      value
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql-0.2.0 lib/graph_ql/query/arguments.rb
graphql-0.1.0 lib/graph_ql/query/arguments.rb