Skip to content

Commit

Permalink
Add promise around resolved
Browse files Browse the repository at this point in the history
@resource.resolve will return either a promise or a real value
  • Loading branch information
MattFenelon committed May 20, 2024
1 parent 7607d2a commit fe6321b
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/graphiti/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,25 @@ def resolve
payload[:results] = @resource.resolve(@object)
payload[:results]
end
resolved.compact!
assign_serializer(resolved)
yield resolved if block_given?
@opts[:after_resolve]&.call(resolved)
p = resolve_sideloads(resolved) unless @query.sideloads.empty?
if p.is_a?(Concurrent::Promises::Future)
p
resolved = Concurrent::Promises.fulfilled_future(resolved) unless resolved.is_a?(Concurrent::Promises::Future)

p = resolved.then_on(self.class.global_thread_pool_executor) do |resolved|
resolved.compact!
assign_serializer(resolved)
yield resolved if block_given?
@opts[:after_resolve]&.call(resolved)
p = resolve_sideloads(resolved) unless @query.sideloads.empty?
if p.is_a?(Concurrent::Promises::Future)
p
else
resolved
end
end

if @query.parents.empty?
p.value!
else
resolved
p.flat
end
end
end
Expand Down

0 comments on commit fe6321b

Please sign in to comment.