Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Nov 5, 2024
1 parent 9dd839c commit 017a0f9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions server/app/controllers/concerns/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def get_trace_mode(request)
return unless Rails.env.production?

query_types = %w[search-genes search-drugs]
if request.headers['dgidb-client-name'] == 'dgidb-frontend' && query_types.include?(request.headers['dgidb-query-type'])
:frontend_analytics
elsif request.headers['RAW_POST_DATA'] && !request.headers['RAW_POST_DATA'].include?('IntrospectionQuery')
if request.headers['dgidb-client-name'] == 'dgidb-frontend'
:frontend_analytics if query_types.include?(request.headers['dgidb-query-type'])
else
:api_analytics
end
end
Expand Down
7 changes: 5 additions & 2 deletions server/app/controllers/graphql_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ def execute
variables = prepare_variables(params[:variables])
query = params[:query]
operation_name = params[:operationName]
trace_mode = Analytics.get_trace_mode(request)
result = DgidbSchema.execute(query, variables: variables, context: { trace_mode: }, operation_name: operation_name)
context = {
trace_mode: Analytics.get_trace_mode(request),
request_ip: request.remote_ip
}
result = DgidbSchema.execute(query, variables: variables, context:, operation_name: operation_name)
render json: result
rescue StandardError => e
raise e unless Rails.env.development?
Expand Down
4 changes: 4 additions & 0 deletions server/app/lib/api_analytics_tracer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module ApiAnalyticsTracer
API_LOGGER = Logger.new(File.join(Rails.root, 'log', 'api-queries.log'))
def analyze_query(query: )
query_type = query.selected_operation.selections&.first&.name

return unless query_type == '__schema'

params = {
user_ip: query.context[:request_ip],
query: query.query_string.squish,
Expand Down

0 comments on commit 017a0f9

Please sign in to comment.