Class: GraphQL::Language::OperationDefinition

Inherits:
Struct
  • Object
show all
Defined in:
lib/graphql/language/operation_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#directivesObject

Returns the value of attribute directives

Returns:

  • (Object)

    the current value of directives



3
4
5
# File 'lib/graphql/language/operation_definition.rb', line 3

def directives
  @directives
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/graphql/language/operation_definition.rb', line 3

def name
  @name
end

#selection_setObject

Returns the value of attribute selection_set

Returns:

  • (Object)

    the current value of selection_set



3
4
5
# File 'lib/graphql/language/operation_definition.rb', line 3

def selection_set
  @selection_set
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



3
4
5
# File 'lib/graphql/language/operation_definition.rb', line 3

def type
  @type
end

#variable_definitionsObject

Returns the value of attribute variable_definitions

Returns:

  • (Object)

    the current value of variable_definitions



3
4
5
# File 'lib/graphql/language/operation_definition.rb', line 3

def variable_definitions
  @variable_definitions
end

Instance Method Details

#evaluate(context) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/graphql/language/operation_definition.rb', line 6

def evaluate(context)
  context[:variables] = materialize_variables(context[:schema], context[:params])
  arguments = [
    type == 'mutation' ? context[:schema].mutation_type : context[:schema].query_type,
    type == 'mutation'
  ]
  execute(context, *arguments)
end

#execute(context, type, serially = false) ⇒ Object



16
17
18
# File 'lib/graphql/language/operation_definition.rb', line 16

def execute(context, type, serially = false)
  selection_set.evaluate(context, type, context[:root], serially: serially)
end

#materialize_variables(schema, params) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/graphql/language/operation_definition.rb', line 21

def materialize_variables(schema, params)
  variable_definitions.reduce({}) do |memo, variable_definition|
    name = variable_definition.variable.name.to_sym
    memo[name] = variable_definition.materialize(schema, params[name])
    memo
  end
end