Sha256: 44fe2979fbfff7ac67cc1cf646a046352a52fada674b7f7a45998d7cf755b3f4

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

require "spec_helper"

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

  it "adds errors for unused fragment definitions" do
    assert_includes(errors, {
      "message"=>"Fragment unusedFields was defined, but not used",
      "locations"=>[{"line"=>8, "column"=>5}],
      "fields"=>[],
    })
  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}],
      "fields"=>["query getCheese", "... undefinedFields"]
    })
  end

  describe "queries that are comments" do
    let(:query_string) {%|
      # I am a comment.
    |}
    let(:result) { DummySchema.execute(query_string) }
    it "handles them gracefully" do
      assert_equal({}, result)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
graphql-1.2.6 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-1.2.5 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-1.2.4 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-1.2.3 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-1.2.2 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-1.2.1 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-1.2.0 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-1.1.0 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-1.0.0 spec/graphql/static_validation/rules/fragments_are_used_spec.rb
graphql-0.19.4 spec/graphql/static_validation/rules/fragments_are_used_spec.rb