Skip to content

Commit d680987

Browse files
committed
more code optimizations.
1 parent f9ad610 commit d680987

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

lib/graphql/stitching/planner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Planner
1111
ROOT_INDEX = 0
1212

1313
class ScopePartition
14-
attr_accessor :location, :selections
14+
attr_reader :location, :selections
1515

1616
def initialize(location:, selections:)
1717
@location = location

lib/graphql/stitching/supergraph.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,17 @@ def route_type_to_locations(type_name, start_location, goal_locations)
187187

188188
private
189189

190-
PathNode = Struct.new(:location, :key, :cost, :resolver, keyword_init: true)
190+
class PathNode
191+
attr_reader :location, :key, :resolver
192+
attr_accessor :cost
193+
194+
def initialize(location:, key:, resolver: nil, cost: 0)
195+
@location = location
196+
@key = key
197+
@resolver = resolver
198+
@cost = cost
199+
end
200+
end
191201

192202
# tunes A* search to favor paths with fewest joining locations, ie:
193203
# favor longer paths through target locations over shorter paths with additional locations.
@@ -196,7 +206,7 @@ def route_type_to_locations_via_search(type_name, start_location, goal_locations
196206
costs = {}
197207

198208
paths = possible_keys_for_type_and_location(type_name, start_location).map do |possible_key|
199-
[PathNode.new(location: start_location, key: possible_key, cost: 0)]
209+
[PathNode.new(location: start_location, key: possible_key)]
200210
end
201211

202212
while paths.any?

lib/graphql/stitching/util.rb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,29 @@ module GraphQL
44
module Stitching
55
# General utilities to aid with stitching.
66
class Util
7-
TypeStructure = Struct.new(:list, :null, :name, keyword_init: true) do
8-
alias_method :list?, :list
9-
alias_method :null?, :null
7+
class TypeStructure
8+
attr_reader :name
9+
10+
def initialize(list:, null:, name:)
11+
@list = list
12+
@null = null
13+
@name = name
14+
end
15+
16+
def list?
17+
@list
18+
end
19+
20+
def null?
21+
@null
22+
end
1023

1124
def non_null?
12-
!null
25+
!@null
26+
end
27+
28+
def ==(other)
29+
@list == other.list? && @null == other.null? && @name == other.name
1330
end
1431
end
1532

0 commit comments

Comments
 (0)