Skip to content

Commit

Permalink
Merge pull request #51 from Shopify/implement-use
Browse files Browse the repository at this point in the history
Make GraphQL::Batch a plugin by adding `use`
  • Loading branch information
swalkinshaw authored Apr 27, 2017
2 parents e807d2b + 4a911e5 commit 9f2cb4c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,23 @@ class RecordLoader < GraphQL::Batch::Loader
end
```

Use lazy execution and instrumentation by `GraphQL::Batch` in your schema
Use `GraphQL::Batch` as a plugin in your schema (for graphql >= `1.5.0`).

```ruby
MySchema = GraphQL::Schema.define do
query MyQueryType

lazy_resolve(Promise, :sync)
instrument(:query, GraphQL::Batch::Setup)
use GraphQL::Batch
end
```

For pre `1.5.0` versions:

```ruby
MySchema = GraphQL::Schema.define do
query MyQueryType

GraphQL::Batch.use(self)
end
```

Expand Down
5 changes: 5 additions & 0 deletions lib/graphql/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def self.batch
end
end

def self.use(schema_defn)
schema_defn.instrument(:query, GraphQL::Batch::Setup)
schema_defn.lazy_resolve(::Promise, :sync)
end

autoload :ExecutionStrategy, 'graphql/batch/execution_strategy'
autoload :MutationExecutionStrategy, 'graphql/batch/mutation_execution_strategy'
end
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/batch/execution_strategy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warn "GraphQL::Batch::ExecutionStrategy is deprecated, instead use `lazy_resolve(Promise, :sync)` and `instrument(:query, GraphQL::Batch::Setup)` in GraphQL::Schema.define"
warn "GraphQL::Batch::ExecutionStrategy is deprecated, instead add `use GraphQL::Batch` in GraphQL::Schema.define"

module GraphQL::Batch
class ExecutionStrategy < GraphQL::Query::SerialExecution
Expand Down
3 changes: 1 addition & 2 deletions test/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,5 @@
query QueryType
mutation MutationType

lazy_resolve(Promise, :sync)
instrument(:query, GraphQL::Batch::Setup)
use GraphQL::Batch
end

0 comments on commit 9f2cb4c

Please sign in to comment.