Class: GraphQL::Stitching::PlannerOperation

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

Constant Summary collapse

LANGUAGE_PRINTER =
GraphQL::Language::Printer.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location:, parent_type:, order:, after: nil, operation_type: "query", selections: [], variables: [], path: [], if_type: nil, boundary: nil) ⇒ PlannerOperation

Returns a new instance of PlannerOperation.



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

def initialize(
  location:,
  parent_type:,
  order:,
  after: nil,
  operation_type: "query",
  selections: [],
  variables: [],
  path: [],
  if_type: nil,
  boundary: nil
)
  @location = location
  @parent_type = parent_type
  @order = order
  @after = after
  @operation_type = operation_type
  @selections = selections
  @variables = variables
  @path = path
  @if_type = if_type
  @boundary = boundary
end

Instance Attribute Details

#afterObject

Returns the value of attribute after.



9
10
11
# File 'lib/graphql/stitching/planner_operation.rb', line 9

def after
  @after
end

#boundaryObject

Returns the value of attribute boundary.



9
10
11
# File 'lib/graphql/stitching/planner_operation.rb', line 9

def boundary
  @boundary
end

#if_typeObject (readonly)

Returns the value of attribute if_type.



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

def if_type
  @if_type
end

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#operation_typeObject (readonly)

Returns the value of attribute operation_type.



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

def operation_type
  @operation_type
end

#orderObject (readonly)

Returns the value of attribute order.



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

def order
  @order
end

#parent_typeObject (readonly)

Returns the value of attribute parent_type.



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

def parent_type
  @parent_type
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#selectionsObject

Returns the value of attribute selections.



9
10
11
# File 'lib/graphql/stitching/planner_operation.rb', line 9

def selections
  @selections
end

#variablesObject

Returns the value of attribute variables.



9
10
11
# File 'lib/graphql/stitching/planner_operation.rb', line 9

def variables
  @variables
end

Instance Method Details

#selection_setObject



35
36
37
38
# File 'lib/graphql/stitching/planner_operation.rb', line 35

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

#to_hObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/graphql/stitching/planner_operation.rb', line 46

def to_h
  data = {
    "order" => @order,
    "after" => @after,
    "location" => @location,
    "operation_type" => @operation_type,
    "selections" => selection_set,
    "variables" => variable_set,
    "path" => @path,
  }

  data["if_type"] = @if_type if @if_type
  data["boundary"] = @boundary if @boundary
  data
end

#variable_setObject



40
41
42
43
44
# File 'lib/graphql/stitching/planner_operation.rb', line 40

def variable_set
  @variables.each_with_object({}) do |(variable_name, value_type), memo|
    memo[variable_name] = LANGUAGE_PRINTER.print(value_type)
  end
end