Module: ArSync::ApiControllerConcern
- Extended by:
- ActiveSupport::Concern
- Includes:
- ArSerializer::Serializable
- Defined in:
- lib/ar_sync/rails.rb
Instance Method Summary collapse
Instance Method Details
#graphql_call ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ar_sync/rails.rb', line 69 def graphql_call render json: ArSerializer::GraphQL.serialize( self, params[:query], operation_name: params[:operationName], variables: (params[:variables] || {}).as_json, context: current_user ) rescue StandardError => e render json: { error: handle_exception(e) } end |
#graphql_schema ⇒ Object
65 66 67 |
# File 'lib/ar_sync/rails.rb', line 65 def graphql_schema render plain: ArSerializer::GraphQL.definition(self.class) end |
#static_call ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ar_sync/rails.rb', line 81 def static_call _api_call :static do |model, current_user, query| case model when ArSync::Collection, ActiveRecord::Relation, Array ArSerializer.serialize model.to_a, query, context: current_user when ActiveRecord::Base ArSerializer.serialize model, query, context: current_user else model end end end |
#sync_call ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ar_sync/rails.rb', line 42 def sync_call _api_call :sync do |model, current_user, query| case model when ArSync::Collection::Graph, ArSync::GraphSync serialized = ArSerializer.serialize model, query, context: current_user, include_id: true, use: :sync next serialized if model.is_a? ArSync::GraphSync { sync_keys: ArSync.sync_graph_keys(model, current_user), order: { mode: model.order, limit: model.limit }, collection: serialized } when ArSync::Collection::Tree ArSync.sync_collection_api model, current_user, query when ActiveRecord::Relation, Array ArSync.serialize model.to_a, query, user: current_user when ActiveRecord::Base ArSync.sync_api model, current_user, query else model end end end |