Sha256: 12688a386fce93b9c6068f05bf49c5b2e9db9a3d12e27ed6f5c8feb586ebc38e

Contents?: true

Size: 1.63 KB

Versions: 40

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::StaticValidation::FieldsHaveAppropriateSelections do
  include StaticValidationHelpers
  let(:query_string) {"
    query getCheese {
      okCheese: cheese(id: 1) { fatContent, similarCheese(source: YAK) { source } }
      missingFieldsCheese: cheese(id: 1)
      illegalSelectionCheese: cheese(id: 1) { id { something, ... someFields } }
    }
  "}

  it "adds errors for selections on scalars" do
    assert_equal(2, errors.length)

    illegal_selection_error = {
      "message"=>"Selections can't be made on scalars (field 'id' returns Int but has selections [something, someFields])",
      "locations"=>[{"line"=>5, "column"=>47}],
      "fields"=>["query getCheese", "illegalSelectionCheese", "id"],
    }
    assert_includes(errors, illegal_selection_error, "finds illegal selections on scalarss")

    selection_required_error = {
      "message"=>"Objects must have selections (field 'cheese' returns Cheese but has no selections)",
      "locations"=>[{"line"=>4, "column"=>7}],
      "fields"=>["query getCheese", "missingFieldsCheese"],
    }
    assert_includes(errors, selection_required_error, "finds objects without selections")
  end

  describe "anonymous operations" do
    let(:query_string) { "{ }" }
    it "requires selections" do
      assert_equal(1, errors.length)

      selections_required_error = {
        "message"=> "Objects must have selections (anonymous query returns Query but has no selections)",
        "locations"=>[{"line"=>1, "column"=>1}],
        "fields"=>["query"]
      }
      assert_includes(errors, selections_required_error)
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
graphql-1.8.0.pre6 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.8.0.pre5 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.7.9 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.8.0.pre4 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.8.0.pre3 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.7.8 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.8.0.pre2 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.7.7 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.8.0.pre1 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.7.6 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.7.5 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.7.4 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.7.3 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.7.2 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.7.1 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.7.0 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.6.8 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.6.7 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.6.6 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-1.6.5 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb