GraphQL::Parallel

Build Status

Provides one layer of asynchronous field resolution to the graphql gem, backed by Celluloid.

Installation

Add this line to your application's Gemfile:

gem 'graphql-parallel'

And then execute:

$ bundle

Or install it yourself as:

$ gem install graphql-parallel

Usage

Require GraphQL::Parallel:

require 'graphql/parallel'

Use context.async in your field resolve functions:

resolve -> (obj, args, context) do
  # resolve other fields while this request
  # is in progress:
  context.async do
    response = Net::HTTP.get_response(obj.uri)
    response.body
  end
end

Use GraphQL::Parallel::ExecutionStrategy for your schema's read queries:

# Define your schema:
MySchema = GraphQL::Schema.new(query: MyQueryType)

# Use parallel execution for read queries:
MySchema.query_execution_strategy = GraphQL::Parallel::ExecutionStrategy

(MySchema will still use the default sequential execution strategy for mutations.)

License

MIT