Class: GraphQL::Query::Variables

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/graphql/query/variables.rb

Overview

Read-only access to query variables, applying default values if needed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, warden, ast_variables, provided_variables) ⇒ Variables

Returns a new instance of Variables


10
11
12
13
14
15
16
17
18
19
# File 'lib/graphql/query/variables.rb', line 10

def initialize(schema, warden, ast_variables, provided_variables)
  @schema = schema
  @warden = warden
  @provided_variables = provided_variables
  @errors = []
  @storage = ast_variables.each_with_object({}) do |ast_variable, memo|
    variable_name = ast_variable.name
    memo[variable_name] = get_graphql_value(ast_variable)
  end
end

Instance Attribute Details

#errorsArray<GraphQL::Query::VariableValidationError> (readonly)

Returns Any errors encountered when parsing the provided variables and literal values

Returns:


8
9
10
# File 'lib/graphql/query/variables.rb', line 8

def errors
  @errors
end

Instance Method Details

#[](key) ⇒ Object


21
22
23
# File 'lib/graphql/query/variables.rb', line 21

def [](key)
  @storage.fetch(key)
end