Sha256: e460e0ee6dbcd1bcdf81b83e6df34841830df32c7d3c0777e401e3b31620b37a

Contents?: true

Size: 1.06 KB

Versions: 8

Compression:

Stored size: 1.06 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) }

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphql-0.15.3 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.15.2 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.14.2 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.15.1 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.15.0 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.14.1 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.14.0 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb
graphql-0.13.0 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb