Class: ZeroRailsAdapter::Processor
- Inherits:
-
Object
- Object
- ZeroRailsAdapter::Processor
- Defined in:
- lib/zero_rails_adapter/processor.rb
Constant Summary collapse
- CLEANUP_MUTATION_NAME =
"_zero_cleanupResults"- DATABASE_ERROR_MESSAGE =
"Database error"- INTERNAL_ERROR_MESSAGE =
"Internal server error"- PERSISTABLE_MUTATION_ERRORS =
[ ActiveModel::UnknownAttributeError, ActiveModel::ValidationError, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotDestroyed, ActiveRecord::RecordNotFound, ActiveRecord::RecordNotSaved ].freeze
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(request:, context:) ⇒ Processor
constructor
A new instance of Processor.
Constructor Details
#initialize(request:, context:) ⇒ Processor
Returns a new instance of Processor.
19 20 21 22 23 |
# File 'lib/zero_rails_adapter/processor.rb', line 19 def initialize(request:, context:) @request = request @context = context.with(request:) @storage = ZeroRailsAdapter.configuration.storage_provider.call(request) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
17 18 19 |
# File 'lib/zero_rails_adapter/processor.rb', line 17 def context @context end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
17 18 19 |
# File 'lib/zero_rails_adapter/processor.rb', line 17 def request @request end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
17 18 19 |
# File 'lib/zero_rails_adapter/processor.rb', line 17 def storage @storage end |
Instance Method Details
#call ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/zero_rails_adapter/processor.rb', line 25 def call responses = [] processed_count = 0 request.mutations.each do |mutation| if mutation.name == CLEANUP_MUTATION_NAME cleanup_results(mutation) processed_count += 1 next end responses << ActiveSupport::Notifications.instrument( "mutation.zero_rails_adapter", name: mutation.name, client_id: mutation.client_id, mutation_id: mutation.id, client_group_id: request.client_group_id, app_id: request.app_id, schema: request.schema ) { process_mutation(mutation) } processed_count += 1 end { "kind" => "MutateResponse", "mutations" => responses, "userID" => context.user_id } rescue OutOfOrderMutationError => error push_failed( reason: "oooMutation", message: error., mutation_ids: request.mutation_ids.drop(processed_count) ) rescue ActiveRecord::ActiveRecordError => error mutation_ids = request.mutation_ids.drop(processed_count) log_push_failure(error, reason: "database", mutation_ids:) push_failed( reason: "database", message: DATABASE_ERROR_MESSAGE, mutation_ids: ) rescue StandardError => error mutation_ids = request.mutation_ids.drop(processed_count) log_push_failure(error, reason: "internal", mutation_ids:) push_failed( reason: "internal", message: INTERNAL_ERROR_MESSAGE, mutation_ids: ) end |