Sha256: 979ae231735011a5e4cf93591f6462cf6567bf0325e95869d6857e0f4dea92d4

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 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)[:errors] }

  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}],
        "fields"=>["query getCheese", "cheese", "... on Milk"],
      },
      {
        "message"=>"Fragment milkFields on Milk can't be spread inside Cheese",
        "locations"=>[{"line"=>4, "column"=>9}],
        "fields"=>["query getCheese", "cheese", "... milkFields"],
      },
      {
        "message"=>"Fragment milkFields on Milk can't be spread inside Cheese",
        "locations"=>[{"line"=>18, "column"=>7}],
        "fields"=>["fragment cheeseFields", "... milkFields"],
      }
    ]
    assert_equal(expected, errors)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql-0.18.15 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb