Class: GraphQL::Stitching::Plan

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

Overview

Immutable structures representing a query plan. May serialize to/from JSON.

Defined Under Namespace

Classes: Op

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ops: []) ⇒ Plan

Returns a new instance of Plan.



58
59
60
# File 'lib/graphql/stitching/plan.rb', line 58

def initialize(ops: [])
  @ops = ops
end

Instance Attribute Details

#opsObject (readonly)

Returns the value of attribute ops.



56
57
58
# File 'lib/graphql/stitching/plan.rb', line 56

def ops
  @ops
end

Class Method Details

.from_json(json) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/graphql/stitching/plan.rb', line 36

def from_json(json)
  ops = json["ops"]
  ops = ops.map do |op|
    boundary = op["boundary"]
    Op.new(
      step: op["step"],
      after: op["after"],
      location: op["location"],
      operation_type: op["operation_type"],
      selections: op["selections"],
      variables: op["variables"],
      path: op["path"],
      if_type: op["if_type"],
      boundary: boundary ? GraphQL::Stitching::Boundary.new(**boundary) : nil,
    )
  end
  new(ops: ops)
end

Instance Method Details

#as_jsonObject



62
63
64
# File 'lib/graphql/stitching/plan.rb', line 62

def as_json
  { ops: @ops.map(&:as_json) }
end