Skip to content

Instantly share code, notes, and snippets.

@jonniesweb
Created March 23, 2018 13:36
Show Gist options
  • Save jonniesweb/6fb89f4050b4b06eff199247bcf16309 to your computer and use it in GitHub Desktop.
Save jonniesweb/6fb89f4050b4b06eff199247bcf16309 to your computer and use it in GitHub Desktop.
Lazily Resolved GraphQL
# app/graphql/ticket_resolver.rb
class TicketResolver
def initialize(id)
@id = id
end
def ticket
if @ticket
@ticket
else
@ticket = BackendTicketService.fetch(@id)
end
end
end
# app/graphql/app_schema.rb
AppSchema = GraphQL::Schema.define do
... # normal GraphQL setup
lazy_resolve(TicketResolver, :ticket)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment