Welcome to mirror list, hosted at ThFree Co, Russian Federation.

logger_analyzer_spec.rb « ast « query_analyzers « graphql « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a5274d49fdbced9b58fa299b3beb9c640a7b8e60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Graphql::QueryAnalyzers::AST::LoggerAnalyzer do
  let(:query) { GraphQL::Query.new(GitlabSchema, document: document, context: {}, variables: { body: 'some note' }) }
  let(:document) do
    GraphQL.parse <<-GRAPHQL
      mutation createNote($body: String!) {
        createNote(input: {noteableId: "gid://gitlab/Noteable/1", body: $body}) {
          note {
            id
          }
        }
      }
    GRAPHQL
  end

  describe '#result' do
    let(:monotonic_time_before) { 42 }
    let(:monotonic_time_after) { 500 }
    let(:monotonic_time_duration) { monotonic_time_after - monotonic_time_before }

    before do
      RequestStore.store[:graphql_logs] = nil

      allow(Gitlab::Metrics::System).to receive(:monotonic_time)
        .and_return(monotonic_time_before, monotonic_time_before,
                    monotonic_time_before, monotonic_time_before,
                    monotonic_time_after)
    end

    it 'returns the complexity, depth, duration, etc' do
      results = GraphQL::Analysis::AST.analyze_query(query, [described_class], multiplex_analyzers: [])
      result = results.first

      expect(result[:duration_s]).to eq monotonic_time_duration
      expect(result[:depth]).to eq 3
      expect(result[:complexity]).to eq 3
      expect(result[:used_fields]).to eq ['Note.id', 'CreateNotePayload.note', 'Mutation.createNote']
      expect(result[:used_deprecated_fields]).to eq []

      request = result.except(:duration_s).merge({
        operation_name: 'createNote',
        variables: { body: "[FILTERED]" }.to_s
      })

      expect(RequestStore.store[:graphql_logs]).to match([request])
    end
  end
end