Class: GraphQL::Stitching::PlannerOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/stitching/planner_operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, location:, parent_type:, operation_type: "query", insertion_path: [], type_condition: nil, after_key: nil, selections: [], variables: [], boundary: nil) ⇒ PlannerOperation

Returns a new instance of PlannerOperation.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/graphql/stitching/planner_operation.rb', line 9

def initialize(
  key:,
  location:,
  parent_type:,
  operation_type: "query",
  insertion_path: [],
  type_condition: nil,
  after_key: nil,
  selections: [],
  variables: [],
  boundary: nil
)
  @key = key
  @after_key = after_key
  @location = location
  @parent_type = parent_type
  @operation_type = operation_type
  @insertion_path = insertion_path
  @type_condition = type_condition
  @selections = selections
  @variables = variables
  @boundary = boundary
end

Instance Attribute Details

#after_keyObject

Returns the value of attribute after_key.



7
8
9
# File 'lib/graphql/stitching/planner_operation.rb', line 7

def after_key
  @after_key
end

#boundaryObject

Returns the value of attribute boundary.



7
8
9
# File 'lib/graphql/stitching/planner_operation.rb', line 7

def boundary
  @boundary
end

#insertion_pathObject (readonly)

Returns the value of attribute insertion_path.



6
7
8
# File 'lib/graphql/stitching/planner_operation.rb', line 6

def insertion_path
  @insertion_path
end

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/graphql/stitching/planner_operation.rb', line 6

def key
  @key
end

#locationObject (readonly)

Returns the value of attribute location.



6
7
8
# File 'lib/graphql/stitching/planner_operation.rb', line 6

def location
  @location
end

#operation_typeObject (readonly)

Returns the value of attribute operation_type.



6
7
8
# File 'lib/graphql/stitching/planner_operation.rb', line 6

def operation_type
  @operation_type
end

#parent_typeObject (readonly)

Returns the value of attribute parent_type.



6
7
8
# File 'lib/graphql/stitching/planner_operation.rb', line 6

def parent_type
  @parent_type
end

#selectionsObject

Returns the value of attribute selections.



7
8
9
# File 'lib/graphql/stitching/planner_operation.rb', line 7

def selections
  @selections
end

#type_conditionObject (readonly)

Returns the value of attribute type_condition.



6
7
8
# File 'lib/graphql/stitching/planner_operation.rb', line 6

def type_condition
  @type_condition
end

#variablesObject

Returns the value of attribute variables.



7
8
9
# File 'lib/graphql/stitching/planner_operation.rb', line 7

def variables
  @variables
end

Instance Method Details

#selection_setObject



33
34
35
36
# File 'lib/graphql/stitching/planner_operation.rb', line 33

def selection_set
  op = GraphQL::Language::Nodes::OperationDefinition.new(selections: @selections)
  GraphQL::Language::Printer.new.print(op).gsub!(/\s+/, " ").strip!
end

#to_hObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/graphql/stitching/planner_operation.rb', line 44

def to_h
  {
    "key" => @key,
    "after_key" => @after_key,
    "location" => @location,
    "operation_type" => @operation_type,
    "insertion_path" => @insertion_path,
    "type_condition" => @type_condition,
    "selections" => selection_set,
    "variables" => variable_set,
    "boundary" => @boundary,
  }
end

#variable_setObject



38
39
40
41
42
# File 'lib/graphql/stitching/planner_operation.rb', line 38

def variable_set
  @variables.each_with_object({}) do |(variable_name, value_type), memo|
    memo[variable_name] = GraphQL::Language::Printer.new.print(value_type)
  end
end