Class: Graphlyte::ArgumentBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/graphlyte/selection_builder.rb

Overview

Helper to build arguments for a field selection.

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ ArgumentBuilder

Returns a new instance of ArgumentBuilder.



11
12
13
# File 'lib/graphlyte/selection_builder.rb', line 11

def initialize(document)
  @document = document
end

Instance Method Details

#build(arguments) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/graphlyte/selection_builder.rb', line 15

def build(arguments)
  return [] unless arguments.any?

  arguments.to_a.map do |(k, v)|
    value = case v
            when Syntax::Value
              v # built via Graphlyte.enum for example
            when SelectionBuilder::Variable
              @document.declare(v)
            when Symbol
              Syntax::VariableReference.new(v.name.camelize)
            else
              Syntax::Value.from_ruby(v)
            end

    Syntax::Argument.new(k.to_s.camelize, value)
  end
end