Last active
April 3, 2018 02:15
-
-
Save jonniesweb/98870831d03616fad49b174ecfc23422 to your computer and use it in GitHub Desktop.
Using Concurrent::Future as return values in GraphQL Ruby
This file contains 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/types/query_type.rb | |
Types::QueryType = GraphQL::ObjectType.define do | |
name "Query" | |
field :ticket, types.String do | |
resolve ->(obj, args, ctx) { | |
Concurrent::Future.execute do | |
BackendTicketService.fetch(1234) | |
end | |
} | |
end | |
end | |
# app/graphql/app_schema.rb | |
AppSchema = GraphQL::Schema.define do | |
query(Types::QueryType) | |
lazy_resolve(Concurrent::Future, :value!) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment