README.md in graphql-batch-0.2.5 vs README.md in graphql-batch-0.3.0
- old
+ new
@@ -47,11 +47,13 @@
```
Use the batch execution strategy with your schema
```ruby
-MySchema = GraphQL::Schema.new(query: MyQueryType)
+MySchema = GraphQL::Schema.define do
+ query MyQueryType
+end
MySchema.query_execution_strategy = GraphQL::Batch::ExecutionStrategy
MySchema.mutation_execution_strategy = GraphQL::Batch::MutationExecutionStrategy
```
The loader class can be used from the resolve proc for a graphql field by calling `.for` with the grouping arguments to get a loader instance, then call `.load` on that instance with the key to load.
@@ -107,29 +109,22 @@
end
```
## Unit Testing
-GraphQL::Batch::Promise#sync can be used to wait for a promise to be resolved and return its result. This can be useful for debugging and unit testing loaders.
+Your loaders can be tested outside of a GraphQL query by doing the
+batch loads in a block passed to GraphQL::Batch.batch. That method
+will set up thread-local state to store the loaders, batch load any
+promise returned from the block then clear the thread-local state
+to avoid leaking state between tests.
```ruby
def test_single_query
product = products(:snowboard)
- query = RecordLoader.for(Product).load(args["id"]).then(&:title)
- assert_equal product.title, query.sync
- end
-```
-
-Use GraphQL::Batch::Promise.all instead of Promise.all to be able to call sync on the returned promise.
-
-```ruby
- def test_batch_query
- products = [products(:snowboard), products(:jacket)]
- query1 = RecordLoader.for(Product).load(products(:snowboard).id).then(&:title)
- query2 = RecordLoader.for(Product).load(products(:jacket).id).then(&:title)
- results = GraphQL::Batch::Promise.all([query1, query2]).sync
- assert_equal products(:snowboard).title, results[0]
- assert_equal products(:jacket).title, results[1]
+ title = GraphQL::Batch.batch do
+ RecordLoader.for(Product).load(product.id).then(&:title)
+ end
+ assert_equal product.title, title
end
```
## Development