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

recursion_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: 997fb129f424c10983ef6bda145373e7fb5b1cde (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Graphql::QueryAnalyzers::AST::RecursionAnalyzer do
  let(:query) { GraphQL::Query.new(GitlabSchema, document: document, context: {}, variables: { body: 'some note' }) }

  context 'when recursion threshold not exceeded' do
    let(:document) do
      GraphQL.parse <<-GRAPHQL
          query recurse {
            group(fullPath: "h5bp") {
              projects {
                nodes {
                  name
                  group {
                    projects {
                      nodes {
                        name
                      }
                    }
                  }
                }
              }
            }
          }
      GRAPHQL
    end

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

      expect(result.first).to be_nil
    end
  end

  context 'when recursion threshold exceeded' do
    let(:document) do
      GraphQL.parse <<-GRAPHQL
          query recurse {
            group(fullPath: "h5bp") {
              projects {
                nodes {
                  name
                  group {
                    projects {
                      nodes {
                        name
                        group {
                          projects {
                            nodes {
                              name
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
      GRAPHQL
    end

    it 'returns error' do
      result = GraphQL::Analysis::AST.analyze_query(query, [described_class], multiplex_analyzers: [])

      expect(result.first.is_a?(GraphQL::AnalysisError)).to be_truthy
    end
  end
end