Sha256: 789b2215a23c4ad246ceb4fdd99ce87aa7699e81aefc724aa81198209e1975d2

Contents?: true

Size: 1.81 KB

Versions: 89

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Analysis::QueryDepth do
  let(:depths) { [] }
  let(:query_depth) { GraphQL::Analysis::QueryDepth.new { |query, max_depth|  depths << query << max_depth } }
  let(:reduce_result) { GraphQL::Analysis.analyze_query(query, [query_depth]) }
  let(:query) { GraphQL::Query.new(Dummy::Schema, query_string, variables: variables) }
  let(:variables) { {} }

  describe "simple queries" do
    let(:query_string) {%|
      query cheeses($isIncluded: Boolean = true){
        # depth of 2
        cheese1: cheese(id: 1) {
          id
          flavor
        }

        # depth of 4
        cheese2: cheese(id: 2) @include(if: $isIncluded) {
          similarCheese(source: SHEEP) {
            ... on Cheese {
              similarCheese(source: SHEEP) {
                id
              }
            }
          }
        }
      }
    |}

    it "finds the max depth" do
      reduce_result
      assert_equal depths, [query, 4]
    end

    describe "with directives" do
      let(:variables) { { "isIncluded" => false } }
      it "doesn't count skipped fields" do
        reduce_result
        assert_equal depths.last, 2
      end
    end
  end

  describe "query with fragments" do
    let(:query_string) {%|
      {
        # depth of 2
        cheese1: cheese(id: 1) {
          id
          flavor
        }

        # depth of 4
        cheese2: cheese(id: 2) {
          ... cheeseFields1
        }
      }

      fragment cheeseFields1 on Cheese {
        similarCheese(source: COW) {
          id
          ... cheeseFields2
        }
      }

      fragment cheeseFields2 on Cheese {
        similarCheese(source: SHEEP) {
          id
        }
      }
    |}

    it "finds the max depth" do
      reduce_result
      assert_equal depths, [query, 4]
    end
  end
end

Version data entries

89 entries across 89 versions & 1 rubygems

Version Path
graphql-1.8.18 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.11 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.10 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.9 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.8 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.7 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.6 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.5 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.4 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.3 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.2 spec/graphql/analysis/query_depth_spec.rb
graphql-1.8.17 spec/graphql/analysis/query_depth_spec.rb
graphql-1.8.16 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.1 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.0 spec/graphql/analysis/query_depth_spec.rb
graphql-1.8.15 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.0.pre4 spec/graphql/analysis/query_depth_spec.rb
graphql-1.8.14 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.0.pre3 spec/graphql/analysis/query_depth_spec.rb
graphql-1.9.0.pre2 spec/graphql/analysis/query_depth_spec.rb