Skip to content

Instantly share code, notes, and snippets.

@bessey
bessey / graphql-ruby-fiber-loading.rb
Last active December 22, 2020 18:24
Proposal for alternative Fiber based design for GraphQL Ruby batched data loading
# The general idea is that similarly to lazy evaluation, the interpreter executes each resolver from inside a Fiber.
# Once we have instantiated a Fiber for every resolver reachable in this pass, we loop over the Fibers, yielding till
# they are dead (the resolver has returned). Resolvers that are not using the Fiber based Loader API would simply
# return there value on the first pass.
# Complete pseudo-cpde, I don't know GraphQL Ruby internals well
def main_graphql_ruby_interpreter_loop(reachable_fields)
unresolved_fields = reachable_fields.reduce({}) do |acc, field|
# Creating one Fiber per field is probably too expensive, and we'd want to re-use them across loops or even across
# different fields in the same loop. A topic for another time.