Class: GraphQL::Execution::VariableValues

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

Overview

Validates and coerces a query's provided variables in a single pass.

Reading methods (#[], #fetch, #to_h, ...) return the values as provided by the client (or the default value from the query string), so that existing callers keep working. Coerced values are available from #coerced_value for the runtime.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, ast_variables, provided_variables) ⇒ VariableValues

Returns a new instance of VariableValues.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/graphql/execution/variable_values.rb', line 21

def initialize(query, ast_variables, provided_variables)
  @query = query
  @context = query.context
  @types = query.types
  @schema = query.schema
  @provided_variables = deep_stringify(provided_variables)
  @errors = []
  @storage = {}
  @coerced_values = {}
  build_values(ast_variables)
end

Instance Attribute Details

#context ⇒ Object (readonly)

Returns the value of attribute context.



19
20
21
# File 'lib/graphql/execution/variable_values.rb', line 19

def context
  @context
end

#errors ⇒ Object (readonly)

Returns

  • Array<GraphQL::Query::VariableValidationError> — Any errors encountered when coercing the provided variables


17
18
19
# File 'lib/graphql/execution/variable_values.rb', line 17

def errors
  @errors
end

Instance Method Details

#coerced_value(name) ⇒ Object

Returns

  • Object — The coerced value for the variable named name, or nil if it wasn't given


38
39
40
# File 'lib/graphql/execution/variable_values.rb', line 38

def coerced_value(name) # :nodoc:
  @coerced_values[name]
end