Sha256: a74a427dc735934583bcdca369e56419248823466aea26a2ccc0719077eec44f

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 KB

Contents

require "spec_helper"

describe GraphQL::StaticValidation::FragmentsAreFinite do
  let(:query_string) {%|
    query getCheese {
      cheese(id: 1) {
        ... idField
        ... sourceField
        ... flavorField
      }
    }

    fragment sourceField on Cheese {
      source,
      ... flavorField
      ... idField
    }
    fragment flavorField on Cheese {
      flavor,
      ... sourceField
    }
    fragment idField on Cheese {
      id
    }
  |}

  let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::FragmentsAreFinite]) }
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
  let(:errors) { validator.validate(query)[:errors] }

  it "doesnt allow infinite loops" do
    expected = [
      {
        "message"=>"Fragment sourceField contains an infinite loop",
        "locations"=>[{"line"=>10, "column"=>5}],
        "path"=>["fragment sourceField"],
      },
      {
        "message"=>"Fragment flavorField contains an infinite loop",
        "locations"=>[{"line"=>15, "column"=>5}],
        "path"=>["fragment flavorField"],
      }
    ]
    assert_equal(expected, errors)
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
graphql-0.18.12 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.11 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.10 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.9 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.8 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.7 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.6 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.5 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.4 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.3 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.2 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.1 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.18.0 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb