Sha256: 5223f0ba1c563d29bd214c0960eaf5c6f40493b97bd1ba9748eab270540cf04e

Contents?: true

Size: 1.32 KB

Versions: 15

Compression:

Stored size: 1.32 KB

Contents

require "spec_helper"

describe GraphQL::StaticValidation::FragmentTypesExist do
  let(:query_string) {"
    query getCheese {
      cheese(id: 1) {
        ... on Cheese { source }
        ... on Nothing { whatever }
        ... somethingFields
        ... cheeseFields
      }
    }

    fragment somethingFields on Something {
      something
    }
    fragment cheeseFields on Cheese {
      fatContent
    }
  "}

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

  it "finds non-existent types on fragments" do
    assert_equal(2, errors.length)
    inline_fragment_error =  {
      "message"=>"No such type Something, so it can't be a fragment condition",
      "locations"=>[{"line"=>11, "column"=>5}],
      "path"=>["fragment somethingFields"],
    }
    assert_includes(errors, inline_fragment_error, "on inline fragments")
    fragment_def_error = {
      "message"=>"No such type Nothing, so it can't be a fragment condition",
      "locations"=>[{"line"=>5, "column"=>9}],
      "path"=>["query getCheese", "cheese", "... on Nothing"],
    }
    assert_includes(errors, fragment_def_error, "on fragment definitions")
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
graphql-0.18.14 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.13 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.12 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.11 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.10 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.9 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.8 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.7 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.6 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.5 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.4 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.3 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.2 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.1 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb
graphql-0.18.0 spec/graphql/static_validation/rules/fragment_types_exist_spec.rb