Skip to content

Commit 79c4a14

Browse files
committed
fix rspecs, README and change TrigerJob
1 parent e94d36f commit 79c4a14

File tree

10 files changed

+27
-36
lines changed

10 files changed

+27
-36
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,20 +350,20 @@ You have the next configuration
350350
# ... other configurations
351351
config.delivery_method = "inline" # the default value "inline", also can be "active_job"
352352
config.queue = "default" # the name of ActiveJob queue
353-
config.job_class = "GraphQL::Adapters::TriggerJob" # the name executor job
353+
config.job_class = "GraphQL::Jobs::TriggerJob" # the name executor job
354354
end
355355
```
356356

357357
`delivery_method` can be either `inline` or `active_job`.
358358
`inline` means that delivering messaging will work sync.
359-
`active_job` - It will adds delivering messages operations to `ActiveJob` with queue `default` and using job `GraphQL::Adapters::TriggerJob`
359+
`active_job` - It will add delivering messages operations to `ActiveJob` with queue `default` and using job `GraphQL::Jobs::TriggerJob`
360360

361-
You can change the queue or job_class, buy changing it in configuration
361+
You can change the queue or job_class by changing it in the configuration
362362

363363
Or you can run code
364364

365365
```ruby
366-
GraphQL::AnyCable.delivery_method("active_job", queue: "broadcasting", job_class: "GraphQL::Adapters::TriggerJob")
366+
GraphQL::AnyCable.delivery_method("active_job", queue: "broadcasting", job_class: "GraphQL::Jobs::TriggerJob")
367367
```
368368

369369
## Testing applications which use `graphql-anycable`

lib/graphql-anycable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def self.stats(**options)
2626
Stats.new(**options).collect
2727
end
2828

29-
def self.delivery_method(kind, queue: "default", job_class: "GraphQL::Adapters::TriggerJob")
29+
def self.delivery_method(kind, queue: "default", job_class: "GraphQL::Jobs::TriggerJob")
3030
config.delivery_method = kind
3131
config.queue = queue
3232
config.job_class = job_class

lib/graphql/adapters/delivery_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def trigger(event_name, args, object, **elements)
3535
def executor_class_job
3636
custom_job_class = config.job_class
3737

38-
return Adapters::TriggerJob unless custom_job_class
38+
return Jobs::TriggerJob unless custom_job_class
3939

4040
custom_job_class.constantize
4141
end

lib/graphql/anycable/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Config < Anyway::Config
1313
attr_config use_client_provided_uniq_id: true
1414
attr_config redis_prefix: "graphql" # Here, we set clear redis_prefix without any hyphen. The hyphen is added at the end of this value on our side.
1515

16-
attr_config delivery_method: "inline", queue: "default", job_class: "GraphQL::Adapters::TriggerJob"
16+
attr_config delivery_method: "inline", queue: "default", job_class: "GraphQL::Jobs::TriggerJob"
1717
end
1818
end
1919
end

lib/graphql/anycable/railtie.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
module GraphQL
66
module AnyCable
77
class Railtie < ::Rails::Railtie
8-
initializer 'graphql_anycable.load_trigger_job' do
9-
#ActiveSupport.on_load(:active_job) do
10-
require "graphql/adapters/trigger_job" if defined?(ActiveJob::Base)
11-
#end
8+
initializer "graphql_anycable.load_trigger_job" do
9+
require "graphql/jobs/trigger_job"
1210
end
1311

14-
1512
rake_tasks do
1613
path = File.expand_path(__dir__)
1714
Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module GraphQL
4-
module Adapters
4+
module Jobs
55
class TriggerJob < ActiveJob::Base
66
def perform(payload, execute_method, event_name, args = {}, object = nil, options = {})
77
schema = schema_parse(payload)

lib/graphql/subscriptions/anycable_subscriptions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ class AnyCableSubscriptions < GraphQL::Subscriptions
5555
extend Forwardable
5656

5757
def_delegators :"GraphQL::AnyCable", :redis, :config
58-
alias_method :trigger_sync, :trigger
5958

6059
attr_reader :collected_arguments
60+
alias_method :trigger_sync, :trigger
6161

6262
SUBSCRIPTION_PREFIX = "subscription:" # HASH: Stores subscription data: query, context, …
6363
FINGERPRINTS_PREFIX = "fingerprints:" # ZSET: To get fingerprints by topic

spec/graphql/anycable_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require "active_job"
4-
require "graphql/adapters/trigger_job"
4+
require "graphql/jobs/trigger_job"
55

66
RSpec.describe GraphQL::AnyCable do
77
subject do
@@ -286,13 +286,13 @@
286286
after do
287287
config.delivery_method = "inline"
288288
config.queue = "default"
289-
config.job_class = "GraphQL::Adapters::TriggerJob"
289+
config.job_class = "GraphQL::Jobs::TriggerJob"
290290
end
291291

292292
it "changes config" do
293293
expect(config.delivery_method).to eq("inline")
294294
expect(config.queue).to eq("default")
295-
expect(config.job_class).to eq("GraphQL::Adapters::TriggerJob")
295+
expect(config.job_class).to eq("GraphQL::Jobs::TriggerJob")
296296

297297
described_class.delivery_method("active_job", queue: "test", job_class: "CustomJob")
298298

spec/graphql/broadcast_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require "active_job"
4-
require "graphql/adapters/trigger_job"
4+
require "graphql/jobs/trigger_job"
55

66
RSpec.describe "Broadcasting" do
77
include_context 'Global ID'
@@ -67,7 +67,7 @@ def subscribe(query)
6767

6868
it "uses broadcasting to resolve query only once" do
6969
2.times { subscribe(query) }
70-
expect_any_instance_of(GraphQL::Adapters::TriggerJob).to receive(:perform).and_call_original
70+
expect_any_instance_of(GraphQL::Jobs::TriggerJob).to receive(:perform).and_call_original
7171

7272
BroadcastSchema.subscriptions.trigger(:post_created, {}, object)
7373

@@ -86,7 +86,7 @@ def subscribe(query)
8686
it "resolves query for every client" do
8787
2.times { subscribe(query) }
8888

89-
expect_any_instance_of(GraphQL::Adapters::TriggerJob).to receive(:perform).and_call_original
89+
expect_any_instance_of(GraphQL::Jobs::TriggerJob).to receive(:perform).and_call_original
9090

9191
BroadcastSchema.subscriptions.trigger(:post_created, {}, object)
9292
expect(object).to have_received(:title).twice
@@ -108,7 +108,7 @@ def subscribe(query)
108108
redis.keys("graphql-subscription:*").last.tap(&redis.method(:del))
109109
expect(redis.keys("graphql-subscription:*").size).to eq(2)
110110

111-
expect_any_instance_of(GraphQL::Adapters::TriggerJob).to receive(:perform).and_call_original
111+
expect_any_instance_of(GraphQL::Jobs::TriggerJob).to receive(:perform).and_call_original
112112

113113
expect { BroadcastSchema.subscriptions.trigger(:post_created, {}, object) }.not_to raise_error
114114
expect(object).to have_received(:title).once
@@ -141,7 +141,7 @@ def subscribe(query)
141141
it "uses broadcasting to resolve query only once" do
142142
2.times { subscribe(query) }
143143

144-
expect_any_instance_of(GraphQL::Adapters::TriggerJob).to_not receive(:perform)
144+
expect_any_instance_of(GraphQL::Jobs::TriggerJob).to_not receive(:perform)
145145

146146
BroadcastSchema.subscriptions.trigger(:post_created, {}, object)
147147
expect(object).to have_received(:title).once
@@ -159,7 +159,7 @@ def subscribe(query)
159159
it "resolves query for every client" do
160160
2.times { subscribe(query) }
161161

162-
expect_any_instance_of(GraphQL::Adapters::TriggerJob).to_not receive(:perform)
162+
expect_any_instance_of(GraphQL::Jobs::TriggerJob).to_not receive(:perform)
163163

164164
BroadcastSchema.subscriptions.trigger(:post_created, {}, object)
165165
expect(object).to have_received(:title).twice
@@ -181,7 +181,7 @@ def subscribe(query)
181181
redis.keys("graphql-subscription:*").last.tap(&redis.method(:del))
182182
expect(redis.keys("graphql-subscription:*").size).to eq(2)
183183

184-
expect_any_instance_of(GraphQL::Adapters::TriggerJob).to_not receive(:perform)
184+
expect_any_instance_of(GraphQL::Jobs::TriggerJob).to_not receive(:perform)
185185

186186
expect { BroadcastSchema.subscriptions.trigger(:post_created, {}, object) }.not_to raise_error
187187
expect(object).to have_received(:title).once
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
require "active_job"
4-
require "graphql/adapters/trigger_job"
4+
require "graphql/jobs/trigger_job"
55

6-
RSpec.describe GraphQL::Adapters::TriggerJob do
6+
RSpec.describe GraphQL::Jobs::TriggerJob do
77
subject(:job) { described_class.perform_later(*job_payload) }
88
subject(:trigger_changes) { AnycableSchema.subscriptions.trigger(*trigger_sync_arguments) }
99

@@ -63,11 +63,8 @@
6363
end
6464

6565
it "executes AnyCableSubscriptions" do
66-
expect_any_instance_of(GraphQL::Subscriptions::AnyCableSubscriptions)
67-
.to receive(:trigger_sync).with(*trigger_sync_arguments)
68-
69-
expect_any_instance_of(GraphQL::Adapters::TriggerJob).to receive(:perform).and_call_original
70-
expect(GraphQL::Adapters::TriggerJob).to receive(:set).with(queue: "default").and_call_original
66+
expect_any_instance_of(GraphQL::Jobs::TriggerJob).to receive(:perform).and_call_original
67+
expect(GraphQL::Jobs::TriggerJob).to receive(:set).with(queue: "default").and_call_original
7168

7269
trigger_changes
7370
end
@@ -83,11 +80,8 @@
8380
end
8481

8582
it "executes AnyCableSubscriptions" do
86-
expect_any_instance_of(GraphQL::Subscriptions::AnyCableSubscriptions)
87-
.to receive(:trigger_sync).with(*trigger_sync_arguments)
88-
89-
expect_any_instance_of(GraphQL::Adapters::TriggerJob).to receive(:perform).and_call_original
90-
expect(GraphQL::Adapters::TriggerJob).to receive(:set).with(queue: "test").and_call_original
83+
expect_any_instance_of(GraphQL::Jobs::TriggerJob).to receive(:perform).and_call_original
84+
expect(GraphQL::Jobs::TriggerJob).to receive(:set).with(queue: "test").and_call_original
9185

9286
trigger_changes
9387
end

0 commit comments

Comments
 (0)