graphql-batch 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4daba918a3d53b660bb662a01fa76be31ab34507
4
- data.tar.gz: a0bf9e1268a286ddd00c1dc60c74769fceb060ae
3
+ metadata.gz: 1d4f407789106fb06ee163d087ba8a0b018d0ff5
4
+ data.tar.gz: 664413f4a7f4776b09d01dd66c23f1a18ab14bc6
5
5
  SHA512:
6
- metadata.gz: 8d532cace4412ef4a5e2aff115841b03590f9a72feb9f75086d1092849f19de4287fa6fd7e8dd4608868283499cf4cea17c414bd718d1c9bdb46c0817d75aac6
7
- data.tar.gz: e6de630224733d0e5dcdcbdea70610910e463862164460e03fe8e4b9f91cca634c28ca2be867d60dd6c3355e13610dac0c5f73edb210daae501e883a0adc0e52
6
+ metadata.gz: 2fc7d6e9e916a0cc7a8e691529749c17b3d47bbdbeadca7b6633c4d9738a36d3ace33892554505e40bfa9ed9246a8d94021771fe276cc45a3bb6ac545eb2e183
7
+ data.tar.gz: 9fc71751db85879738f84601692f27781a8207564a4e38f1ffa3981d57421df9322943b232925a8e4b3662b4f232d63e002f6b9cc983e148cb764a0db11c2e52
data/README.md CHANGED
@@ -48,7 +48,7 @@ Use the batch execution strategy with your schema
48
48
  ```ruby
49
49
  MySchema = GraphQL::Schema.new(query: MyQueryType)
50
50
  MySchema.query_execution_strategy = GraphQL::Batch::ExecutionStrategy
51
- MySchema.mutation_execution_strategy = GraphQL::Batch::ExecutionStrategy
51
+ MySchema.mutation_execution_strategy = GraphQL::Batch::MutationExecutionStrategy
52
52
  ```
53
53
 
54
54
  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.
data/lib/graphql/batch.rb CHANGED
@@ -12,3 +12,4 @@ require_relative "batch/loader"
12
12
  require_relative "batch/executor"
13
13
  require_relative "batch/promise"
14
14
  require_relative "batch/execution_strategy"
15
+ require_relative "batch/mutation_execution_strategy"
@@ -28,6 +28,10 @@ module GraphQL::Batch
28
28
  end
29
29
  end
30
30
 
31
+ def wait_all
32
+ tick until loaders.empty?
33
+ end
34
+
31
35
  def clear
32
36
  loaders.clear
33
37
  end
@@ -0,0 +1,20 @@
1
+ module GraphQL::Batch
2
+ class MutationExecutionStrategy < GraphQL::Query::SerialExecution
3
+ class FieldResolution < GraphQL::Query::SerialExecution::FieldResolution
4
+ def get_finished_value(raw_value)
5
+ raw_value = GraphQL::Batch::Promise.resolve(raw_value).sync
6
+
7
+ context = execution_context.query.context
8
+ old_execution_strategy = context.execution_strategy
9
+ begin
10
+ context.execution_strategy = GraphQL::Batch::ExecutionStrategy.new
11
+ result = super(raw_value)
12
+ GraphQL::Batch::Executor.current.wait_all
13
+ result
14
+ ensure
15
+ context.execution_strategy = old_execution_strategy
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  module Graphql
2
2
  module Batch
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-batch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Thacker-Smith
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-21 00:00:00.000000000 Z
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -114,6 +114,7 @@ files:
114
114
  - lib/graphql/batch/execution_strategy.rb
115
115
  - lib/graphql/batch/executor.rb
116
116
  - lib/graphql/batch/loader.rb
117
+ - lib/graphql/batch/mutation_execution_strategy.rb
117
118
  - lib/graphql/batch/promise.rb
118
119
  - lib/graphql/batch/version.rb
119
120
  homepage: https://github.com/Shopify/graphql-batch