Class: GQL::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/gql/executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast_query) ⇒ Executor

Returns a new instance of Executor.



5
6
7
8
# File 'lib/gql/executor.rb', line 5

def initialize(ast_query)
  @ast_root   = ast_query.root
  @variables  = ast_query.variables
end

Instance Attribute Details

#ast_rootObject (readonly)

Returns the value of attribute ast_root.



3
4
5
# File 'lib/gql/executor.rb', line 3

def ast_root
  @ast_root
end

#variablesObject (readonly)

Returns the value of attribute variables.



3
4
5
# File 'lib/gql/executor.rb', line 3

def variables
  @variables
end

Instance Method Details

#execute(context = {}, vars = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gql/executor.rb', line 10

def execute(context = {}, vars = {})
  field_class = GQL.root_class

  raise Errors::RootClassNotSet if field_class.nil?

  variables.update vars

  target = GQL.root_target_proc.call(context)

  field = Registry.fetch(field_class).new(ast_root, target, variables, context)
  field.value
end