Skip to content

Commit aa81e7a

Browse files
committed
refactor(Execution) move exec_ objects to own files
1 parent 97ad083 commit aa81e7a

File tree

6 files changed

+84
-68
lines changed

6 files changed

+84
-68
lines changed

lib/graphql/execution.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
require "graphql/execution/deferred_execution"
22
require "graphql/execution/directive_checks"
3+
require "graphql/execution/exec_frame"
4+
require "graphql/execution/exec_scope"
5+
require "graphql/execution/exec_stream"
6+
require "graphql/execution/exec_thread"
37
require "graphql/execution/typecast"

lib/graphql/execution/deferred_execution.rb

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -165,74 +165,6 @@ def execute(ast_operation, root_type, query_object)
165165
initial_result
166166
end
167167

168-
# Global, immutable environment for executing `query`.
169-
# Passed through all execution to provide type, fragment and field lookup.
170-
class ExecScope
171-
attr_reader :query, :schema
172-
173-
def initialize(query)
174-
@query = query
175-
@schema = query.schema
176-
end
177-
178-
def get_type(type)
179-
@schema.types[type]
180-
end
181-
182-
def get_fragment(name)
183-
@query.fragments[name]
184-
end
185-
186-
# This includes dynamic fields like __typename
187-
def get_field(type, name)
188-
@schema.get_field(type, name) || raise("No field named '#{name}' found for #{type}")
189-
end
190-
end
191-
192-
# One serial stream of execution. One thread runs the initial query,
193-
# then any deferred frames are restarted with their own threads.
194-
#
195-
# - {ExecThread#errors} contains errors during this part of the query
196-
# - {ExecThread#defers} contains {ExecFrame}s which were marked as `@defer`
197-
# and will be executed with their own threads later.
198-
class ExecThread
199-
attr_reader :errors, :defers
200-
def initialize
201-
@errors = []
202-
@defers = []
203-
end
204-
end
205-
206-
# One step of execution. Each step in execution gets its own frame.
207-
#
208-
# - {ExecFrame#node} is the IRep node which is being interpreted
209-
# - {ExecFrame#path} is like a stack trace, it is used for patching deferred values
210-
# - {ExecFrame#value} is the object being exposed by GraphQL at this point
211-
# - {ExecFrame#type} is the GraphQL type which exposes {#value} at this point
212-
class ExecFrame
213-
attr_reader :node, :path, :type, :value
214-
def initialize(node:, path:, type:, value:)
215-
@node = node
216-
@path = path
217-
@type = type
218-
@value = value
219-
end
220-
end
221-
222-
# Contains the list field's ExecFrame
223-
# And the enumerator which is being mapped
224-
# - {ExecStream#enumerator} is an Enumerator which yields `item, idx`
225-
# - {ExecStream#frame} is the {ExecFrame} for the list selection (where `@stream` was present)
226-
# - {ExecStream#type} is the inner type of the list (the item's type)
227-
class ExecStream
228-
attr_reader :enumerator, :frame, :type
229-
def initialize(enumerator:, frame:, type:)
230-
@enumerator = enumerator
231-
@frame = frame
232-
@type = type
233-
end
234-
end
235-
236168
private
237169

238170
# If this `frame` is marked as defer, add it to `defers`

lib/graphql/execution/exec_frame.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module GraphQL
2+
module Execution
3+
# One step of execution. Each step in execution gets its own frame.
4+
#
5+
# - {ExecFrame#node} is the IRep node which is being interpreted
6+
# - {ExecFrame#path} is like a stack trace, it is used for patching deferred values
7+
# - {ExecFrame#value} is the object being exposed by GraphQL at this point
8+
# - {ExecFrame#type} is the GraphQL type which exposes {#value} at this point
9+
class ExecFrame
10+
attr_reader :node, :path, :type, :value
11+
def initialize(node:, path:, type:, value:)
12+
@node = node
13+
@path = path
14+
@type = type
15+
@value = value
16+
end
17+
end
18+
end
19+
end

lib/graphql/execution/exec_scope.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module GraphQL
2+
module Execution
3+
# Global, immutable environment for executing `query`.
4+
# Passed through all execution to provide type, fragment and field lookup.
5+
class ExecScope
6+
attr_reader :query, :schema
7+
8+
def initialize(query)
9+
@query = query
10+
@schema = query.schema
11+
end
12+
13+
def get_type(type)
14+
@schema.types[type]
15+
end
16+
17+
def get_fragment(name)
18+
@query.fragments[name]
19+
end
20+
21+
# This includes dynamic fields like __typename
22+
def get_field(type, name)
23+
@schema.get_field(type, name) || raise("No field named '#{name}' found for #{type}")
24+
end
25+
end
26+
end
27+
end

lib/graphql/execution/exec_stream.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module GraphQL
2+
module Execution
3+
# Contains the list field's ExecFrame
4+
# And the enumerator which is being mapped
5+
# - {ExecStream#enumerator} is an Enumerator which yields `item, idx`
6+
# - {ExecStream#frame} is the {ExecFrame} for the list selection (where `@stream` was present)
7+
# - {ExecStream#type} is the inner type of the list (the item's type)
8+
class ExecStream
9+
attr_reader :enumerator, :frame, :type
10+
def initialize(enumerator:, frame:, type:)
11+
@enumerator = enumerator
12+
@frame = frame
13+
@type = type
14+
end
15+
end
16+
end
17+
end

lib/graphql/execution/exec_thread.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module GraphQL
2+
module Execution
3+
# One serial stream of execution. One thread runs the initial query,
4+
# then any deferred frames are restarted with their own threads.
5+
#
6+
# - {ExecThread#errors} contains errors during this part of the query
7+
# - {ExecThread#defers} contains {ExecFrame}s which were marked as `@defer`
8+
# and will be executed with their own threads later.
9+
class ExecThread
10+
attr_reader :errors, :defers
11+
def initialize
12+
@errors = []
13+
@defers = []
14+
end
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)