Sha256: b6270b6ef322b31736749236ec1beedbefce1d60b75ca11d8340027ac48b8d2d

Contents?: true

Size: 1.78 KB

Versions: 35

Compression:

Stored size: 1.78 KB

Contents

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(DummySchema, 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

35 entries across 35 versions & 1 rubygems

Version Path
graphql-1.2.6 spec/graphql/analysis/query_depth_spec.rb
graphql-1.2.5 spec/graphql/analysis/query_depth_spec.rb
graphql-1.2.4 spec/graphql/analysis/query_depth_spec.rb
graphql-1.2.3 spec/graphql/analysis/query_depth_spec.rb
graphql-1.2.2 spec/graphql/analysis/query_depth_spec.rb
graphql-1.2.1 spec/graphql/analysis/query_depth_spec.rb
graphql-1.2.0 spec/graphql/analysis/query_depth_spec.rb
graphql-1.1.0 spec/graphql/analysis/query_depth_spec.rb
graphql-1.0.0 spec/graphql/analysis/query_depth_spec.rb
graphql-0.19.4 spec/graphql/analysis/query_depth_spec.rb
graphql-0.19.3 spec/graphql/analysis/query_depth_spec.rb
graphql-0.19.2 spec/graphql/analysis/query_depth_spec.rb
graphql-0.19.1 spec/graphql/analysis/query_depth_spec.rb
graphql-0.19.0 spec/graphql/analysis/query_depth_spec.rb
graphql-0.18.15 spec/graphql/analysis/query_depth_spec.rb
graphql-0.18.14 spec/graphql/analysis/query_depth_spec.rb
graphql-0.18.13 spec/graphql/analysis/query_depth_spec.rb
graphql-0.18.12 spec/graphql/analysis/query_depth_spec.rb
graphql-0.18.11 spec/graphql/analysis/query_depth_spec.rb
graphql-0.18.10 spec/graphql/analysis/query_depth_spec.rb