Sha256: 956091551c722ec90c4583bc85de72f3e8650cdd6df063ad5557a832dc7ca08f
Contents?: true
Size: 1010 Bytes
Versions: 4
Compression:
Stored size: 1010 Bytes
Contents
require 'forwardable' # Provide read-only access to arguments by string or symbol names. class GraphQL::Query::Arguments extend Forwardable def initialize(ast_arguments, argument_hash, variables) @hash = ast_arguments.reduce({}) do |memo, arg| arg_defn = argument_hash[arg.name] value = reduce_value(arg.value, arg_defn, variables) memo[arg.name] = value memo end end def_delegators :@hash, :keys, :values, :inspect, :to_h def [](key) @hash[key.to_s] end private def reduce_value(value, arg_defn, variables) if value.is_a?(GraphQL::Language::Nodes::VariableIdentifier) value = variables[value.name] elsif value.is_a?(GraphQL::Language::Nodes::Enum) value = arg_defn.type.coerce(value.name) elsif value.is_a?(GraphQL::Language::Nodes::InputObject) wrapped_type = arg_defn.type.kind.unwrap(arg_defn.type) value = self.class.new(value.pairs, wrapped_type.input_fields, variables) else value end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
graphql-0.7.1 | lib/graphql/query/arguments.rb |
graphql-0.7.0 | lib/graphql/query/arguments.rb |
graphql-0.6.2 | lib/graphql/query/arguments.rb |
graphql-0.6.1 | lib/graphql/query/arguments.rb |