diff options
Diffstat (limited to 'spec/requests/api/graphql_spec.rb')
-rw-r--r-- | spec/requests/api/graphql_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/requests/api/graphql_spec.rb b/spec/requests/api/graphql_spec.rb index cca87c16f27..656d6f8b50b 100644 --- a/spec/requests/api/graphql_spec.rb +++ b/spec/requests/api/graphql_spec.rb @@ -16,6 +16,54 @@ describe 'GraphQL' do end end + context 'logging' do + shared_examples 'logging a graphql query' do + let(:expected_params) do + { query_string: query, variables: variables.to_s, duration: anything, depth: 1, complexity: 1 } + end + + it 'logs a query with the expected params' do + expect(Gitlab::GraphqlLogger).to receive(:info).with(expected_params).once + + post_graphql(query, variables: variables) + end + + it 'does not instantiate any query analyzers' do # they are static and re-used + expect(GraphQL::Analysis::QueryComplexity).not_to receive(:new) + expect(GraphQL::Analysis::QueryDepth).not_to receive(:new) + + 2.times { post_graphql(query, variables: variables) } + end + end + + context 'with no variables' do + let(:variables) { {} } + + it_behaves_like 'logging a graphql query' + end + + context 'with variables' do + let(:variables) do + { "foo" => "bar" } + end + + it_behaves_like 'logging a graphql query' + end + + context 'when there is an error in the logger' do + before do + allow_any_instance_of(Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer).to receive(:process_variables).and_raise(StandardError.new("oh noes!")) + end + + it 'logs the exception in Sentry and continues with the request' do + expect(Gitlab::Sentry).to receive(:track_exception).at_least(1).times + expect(Gitlab::GraphqlLogger).to receive(:info) + + post_graphql(query, variables: {}) + end + end + end + context 'invalid variables' do it 'returns an error' do post_graphql(query, variables: "This is not JSON") |