Sha256: 3b5c97cb975408debc1c1053ff9f33e0c5d2936e6ab5721b3851b99b5c980c41

Contents?: true

Size: 942 Bytes

Versions: 8

Compression:

Stored size: 942 Bytes

Contents

require "spec_helper"

describe GraphQL::StaticValidation::FragmentsAreUsed do
  let(:query_string) {"
    query getCheese {
      name,
      ...cheeseFields
      ...undefinedFields
    }
    fragment cheeseFields on Cheese { fatContent }
    fragment unusedFields on Cheese { is, not, used }
  "}

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

  it "adds errors for unused fragment definitions" do
    assert_includes(errors, {"message"=>"Fragment unusedFields was defined, but not used", "locations"=>[{"line"=>8, "column"=>5}]})
  end

  it "adds errors for undefined fragment spreads" do
    assert_includes(errors, {"message"=>"Fragment undefinedFields was used, but not defined", "locations"=>[{"line"=>5, "column"=>7}]})
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphql-0.15.3 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-0.15.2 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-0.14.2 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-0.15.1 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-0.15.0 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-0.14.1 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-0.14.0 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-0.13.0 spec/graphql/static_validation/rules/fragments_are_used_spec.rb