Sha256: aa1b5a729ba4190f4400094d54df58721cc86b04e2e386d48b7880f63a52f0d5

Contents?: true

Size: 1.4 KB

Versions: 76

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::StaticValidation::FragmentSpreadsArePossible do
  include StaticValidationHelpers

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

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

  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

76 entries across 76 versions & 1 rubygems

Version Path
graphql-1.8.18 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.17 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.16 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.15 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.14 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.13 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.12 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.9.0.pre1 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.11 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.10 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.9 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.8 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.7 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.6 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.5 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.4 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.3 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.2 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.1 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb
graphql-1.8.0 spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb