Sha256: 5241affacf6d9e1ea54b01e0ef826414dcb09b9743f4d67a0c47292506e4142c

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require "spec_helper"

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

    fragment sourceField on Cheese {
      source,
      ... flavorField
      ... idField
    }
    fragment flavorField on Cheese {
      flavor,
      similarCheese {
        ... 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"=>12, "column"=>5}],
        "path"=>["fragment sourceField"],
      },
      {
        "message"=>"Fragment flavorField contains an infinite loop",
        "locations"=>[{"line"=>17, "column"=>5}],
        "path"=>["fragment flavorField"],
      }
    ]
    assert_equal(expected, errors)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql-0.18.13 spec/graphql/static_validation/rules/fragments_are_finite_spec.rb