Commit 7498a293 authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Add GraphQL information to logs

This new log field can be extended in the future to have more granular
data to navigate the logs better.
parent c3d28b68
...@@ -107,4 +107,12 @@ class GraphqlController < ApplicationController ...@@ -107,4 +107,12 @@ class GraphqlController < ApplicationController
render json: error, status: status render json: error, status: status
end end
def append_info_to_payload(payload)
super
# Merging to :metadata will ensure these are logged as top level keys
payload[:metadata] ||= {}
payload[:metadata].merge!(graphql: { operation_name: params[:operationName] })
end
end end
...@@ -147,4 +147,22 @@ RSpec.describe GraphqlController do ...@@ -147,4 +147,22 @@ RSpec.describe GraphqlController do
end end
end end
end end
describe '#append_info_to_payload' do
let(:graphql_query) { graphql_query_for('project', { 'fullPath' => 'foo' }, %w(id name)) }
let(:log_payload) { {} }
before do
allow(controller).to receive(:append_info_to_payload).and_wrap_original do |method, *|
method.call(log_payload)
end
end
it 'appends metadata for logging' do
post :execute, params: { query: graphql_query, operationName: 'Foo' }
expect(controller).to have_received(:append_info_to_payload)
expect(log_payload.dig(:metadata, :graphql, :operation_name)).to eq('Foo')
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment