Sha256: 519c37232f7bd14c33405d5b55662c837ed7c67e59869d51cfd1b5e4bc65632a

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

require "spec_helper"

describe GraphQL::StaticValidation::FragmentSpreadsArePossible do
  let(:query_string) {%|
    query getCheese {
      cheese(id: 1) {
        ... milkFields
        ... cheeseFields
        ... on Milk { fatContent }
        ... on AnimalProduct { source }
        ... on DairyProduct {
          fatContent
          ... on Edible { fatContent }
        }
      }
    }

    fragment milkFields on Milk { fatContent }
    fragment cheeseFields on Cheese {
      fatContent
      ... milkFields
    }
  |}

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

  it "doesnt allow spreads where they'll never apply" do
    # TODO: more negative, abstract examples here, add stuff to the schema
    expected = [
      {
        "message"=>"Fragment on Milk can't be spread inside Cheese",
        "locations"=>[{"line"=>6, "column"=>9}]
      },
      {
        "message"=>"Fragment milkFields on Milk can't be spread inside Cheese",
        "locations"=>[{"line"=>4, "column"=>9}]
      },
      {
        "message"=>"Fragment milkFields on Milk can't be spread inside Cheese",
        "locations"=>[{"line"=>18, "column"=>7}]
      }
    ]
    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/fragment_spreads_are_possible_spec.rb
graphql-0.15.2 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-0.14.2 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-0.15.1 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-0.15.0 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-0.14.1 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-0.14.0 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-0.13.0 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb