-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
646d680
commit e94d36f
Showing
15 changed files
with
419 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module GraphQL | ||
module Adapters | ||
class DeliveryAdapter | ||
DELIVERY_METHOD_INLINE = "inline" | ||
DELIVERY_METHOD_ACTIVE_JOB = "active_job" | ||
|
||
attr_reader :executor_object, :executor_method | ||
|
||
def initialize(executor_object:) | ||
@executor_object = executor_object | ||
@executor_method = executor_object.class::EXECUTOR_METHOD_NAME | ||
end | ||
|
||
def trigger(event_name, args, object, **elements) | ||
if config.delivery_method == DELIVERY_METHOD_INLINE | ||
return executor_object.public_send(executor_method, event_name, args, object, **elements) | ||
end | ||
|
||
return if config.delivery_method != DELIVERY_METHOD_ACTIVE_JOB | ||
|
||
executor_class_job.set(queue: config.queue).perform_later( | ||
executor_object.collected_arguments, | ||
executor_method, | ||
event_name, | ||
args, | ||
object, | ||
elements | ||
) | ||
end | ||
|
||
private | ||
|
||
def executor_class_job | ||
custom_job_class = config.job_class | ||
|
||
return Adapters::TriggerJob unless custom_job_class | ||
|
||
custom_job_class.constantize | ||
end | ||
|
||
def config | ||
GraphQL::AnyCable.config | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module GraphQL | ||
module Adapters | ||
class TriggerJob < ActiveJob::Base | ||
def perform(payload, execute_method, event_name, args = {}, object = nil, options = {}) | ||
schema = schema_parse(payload) | ||
|
||
schema.public_send(execute_method, event_name, args, object, **options) | ||
end | ||
|
||
private | ||
|
||
def schema_parse(serialized_payload) | ||
payload = serialized_payload | ||
|
||
payload[:schema] = payload[:schema].safe_constantize | ||
payload[:serializer] = payload[:serializer].safe_constantize | ||
|
||
GraphQL::Subscriptions::AnyCableSubscriptions.new(**payload) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.