graphql-batch 0.4.1 → 0.4.2

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
  SHA256:
3
- metadata.gz: 91e74a8bcaef766442554972512d2e294e45e69a694958a3e5d1d21d72d0561c
4
- data.tar.gz: 9304331994c9b8065e0f531c32eab90dff638e340ed43554d2e3d2188d255a1d
3
+ metadata.gz: 257c2068b92162f1e38b17192c08979fdfcd04fe4f4fa93d2a290dc3746e12ec
4
+ data.tar.gz: 4b050c894e800925946423723a6431c5a28f3486c4f5de6f2e80c73ed578db18
5
5
  SHA512:
6
- metadata.gz: 573581325fe65a14189848de43ebbf73d8affe7160e337c4a199a73e27d62c6073e2a233a51fc30ab278f028bd6258c3d0c2b8cb0521b21fe21c2c96fe82d534
7
- data.tar.gz: 4d49402c2de01bfbe3c65637b8701a269d80bd15dc8164d91bb91454414a6c1efec90826fcf5e6dd645f0d575fadea3a74bc4b34d9cf5f49cb98015089532299
6
+ metadata.gz: 5f2d63cc78370652458bc351d5d05f0502f7429c66e4bd0676b1fd62eea0fc9a6eb359d7df9213a3be413bbcd81b29a425e300c8c9f21769b13a0e91864e59b7
7
+ data.tar.gz: 0d35c4b83c8f8d732dc24889b16a4ad672e308582b4aab9c2a7f84da6d8388a5df8e0ae5adcca4e5ccb538b5c2f2568e772c635bff31663bb1620358ee98e3f6
data/Gemfile CHANGED
@@ -3,5 +3,5 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  if ENV["TESTING_INTERPRETER"] == "true"
6
- gem "graphql", "1.9.0.pre4"
6
+ gem "graphql", "1.10.0.pre2"
7
7
  end
data/README.md CHANGED
@@ -143,11 +143,11 @@ end
143
143
  ```ruby
144
144
  def product(id:)
145
145
  # Try the cache first ...
146
- CacheLoader.for(Product).load(args["id"]).then(nil, lambda do |exc|
146
+ CacheLoader.for(Product).load(id).then(nil, lambda do |exc|
147
147
  # But if there's a connection error, go to the underlying database
148
148
  raise exc unless exc.is_a?(Redis::BaseConnectionError)
149
149
  logger.warn err.message
150
- RecordLoader.for(Product).load(args["id"])
150
+ RecordLoader.for(Product).load(id)
151
151
  end)
152
152
  end
153
153
  ```
@@ -0,0 +1,65 @@
1
+ # A sample HTTP loader using:
2
+ #
3
+ # 1. https://github.com/httprb/http
4
+ # 2. https://github.com/mperham/connection_pool
5
+ # 3. https://github.com/ruby-concurrency/concurrent-ruby
6
+ #
7
+ # Setup:
8
+ #
9
+ # field :weather, String, null: true do
10
+ # argument :lat, Float, required: true
11
+ # argument :lng, Float, required: true
12
+ # argument :lang, String, required: true
13
+ # end
14
+ #
15
+ # def weather(lat:, lng:, lang:)
16
+ # key = Rails.application.credentials.darksky_key
17
+ # path = "/forecast/#{key}/#{lat},#{lng}?lang=#{lang}"
18
+ # Loaders::HTTPLoader
19
+ # .for(host: 'https://api.darksky.net')
20
+ # .load(->(connection) { connection.get(path).flush })
21
+ # .then do |response|
22
+ # if response.status.ok?
23
+ # json = JSON.parse(response.body)
24
+ # json['currently']['summary']
25
+ # end
26
+ # end
27
+ # end
28
+ #
29
+ # Querying:
30
+ #
31
+ # <<~GQL
32
+ # query Weather {
33
+ # montreal: weather(lat: 45.5017, lng: -73.5673, lang: "fr")
34
+ # waterloo: weather(lat: 43.4643, lng: -80.5204, lang: "en")
35
+ # }
36
+ # GQL
37
+
38
+ module Loaders
39
+ class HTTPLoader < GraphQL::Batch::Loader
40
+ def initialize(host:, size: 4, timeout: 4)
41
+ @host = host
42
+ @size = size
43
+ @timeout = timeout
44
+ end
45
+
46
+ def perform(operations)
47
+ futures = operations.map do |operation|
48
+ Concurrent::Promises.future do
49
+ pool.with { |connection| operation.call(connection) }
50
+ end
51
+ end
52
+ operations.each_with_index.each do |operation, index|
53
+ fulfill(operation, futures[index].value)
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def pool
60
+ @pool ||= ConnectionPool.new(size: @size, timeout: @timeout) do
61
+ HTTP.persistent(@host)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -16,16 +16,18 @@ module GraphQL
16
16
  end
17
17
 
18
18
  def self.use(schema_defn, executor_class: GraphQL::Batch::Executor)
19
- schema = schema_defn.target
20
- if GraphQL::VERSION >= "1.6.0"
19
+ # Support 1.10+ which passes the class instead of the definition proxy
20
+ schema = schema_defn.is_a?(Class) ? schema_defn : schema_defn.target
21
+ current_gem_version = Gem::Version.new(GraphQL::VERSION)
22
+ if current_gem_version >= Gem::Version.new("1.6.0")
21
23
  instrumentation = GraphQL::Batch::SetupMultiplex.new(schema, executor_class: executor_class)
22
24
  schema_defn.instrument(:multiplex, instrumentation)
23
25
  if schema.mutation
24
- if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.9.0.pre3') &&
25
- schema.mutation.metadata[:type_class]
26
+ if current_gem_version >= Gem::Version.new('1.9.0.pre3') &&
27
+ (schema.mutation.is_a?(Class) || schema.mutation.metadata[:type_class])
26
28
  require_relative "batch/mutation_field_extension"
27
29
  schema.mutation.fields.each do |name, f|
28
- field = f.metadata[:type_class]
30
+ field = f.respond_to?(:type_class) ? f.type_class : f.metadata[:type_class]
29
31
  field.extension(GraphQL::Batch::MutationFieldExtension)
30
32
  end
31
33
  else
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Batch
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
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.4.1
4
+ version: 0.4.2
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: 2019-07-18 00:00:00.000000000 Z
11
+ date: 2019-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -103,6 +103,7 @@ files:
103
103
  - bin/console
104
104
  - bin/setup
105
105
  - examples/association_loader.rb
106
+ - examples/http_loader.rb
106
107
  - examples/record_loader.rb
107
108
  - graphql-batch.gemspec
108
109
  - lib/graphql/batch.rb
@@ -131,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  - !ruby/object:Gem::Version
132
133
  version: '0'
133
134
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.7.6
135
+ rubygems_version: 3.0.3
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: A query batching executor for the graphql gem