Created
March 23, 2018 13:36
-
-
Save jonniesweb/6fb89f4050b4b06eff199247bcf16309 to your computer and use it in GitHub Desktop.
Lazily Resolved GraphQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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