Sha256: a7ea278b2056edc2c2ff464d696cc76dd70b37bc70ae9a5d59fcbe765608d480

Contents?: true

Size: 1.56 KB

Versions: 18

Compression:

Stored size: 1.56 KB

Contents

require "spec_helper"

describe GraphQL::Analysis::FieldUsage do
  let(:result) { [] }
  let(:field_usage_analyzer) { GraphQL::Analysis::FieldUsage.new { |query, used_fields, used_deprecated_fields| result << query << used_fields << used_deprecated_fields } }
  let(:reduce_result) { GraphQL::Analysis.analyze_query(query, [field_usage_analyzer]) }
  let(:query) { GraphQL::Query.new(DummySchema, query_string, variables: variables) }
  let(:variables) { {} }

  describe "query with deprecated fields" do
    let(:query_string) {%|
      query {
        cheese(id: 1) {
          id
          fatContent
        }
      }
    |}

    it "returns query in reduced result" do
      reduce_result
      assert_equal query, result[0]
    end

    it "keeps track of used fields" do
      reduce_result
      assert_equal ['Cheese.id', 'Cheese.fatContent', 'Query.cheese'], result[1]
    end

    it "keeps track of deprecated fields" do
      reduce_result
      assert_equal ['Cheese.fatContent'], result[2]
    end
  end

  describe "query with deprecated fields used more than once" do
    let(:query_string) {%|
      query {
        cheese1: cheese(id: 1) {
          id
          fatContent
        }

        cheese2: cheese(id: 2) {
          id
          fatContent
        }
      }
    |}

    it "omits duplicate usage of a field" do
      reduce_result
      assert_equal ['Cheese.id', 'Cheese.fatContent', 'Query.cheese'], result[1]
    end

    it "omits duplicate usage of a deprecated field" do
      reduce_result
      assert_equal ['Cheese.fatContent'], result[2]
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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