Sha256: 9f73830b24d23c6f3b873334a4abf6eaf212a7431680c317504f104eee4e1c7d

Contents?: true

Size: 1.4 KB

Versions: 15

Compression:

Stored size: 1.4 KB

Contents

require "spec_helper"

describe GraphQL::StaticValidation::FieldsHaveAppropriateSelections do
  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 } }
    }
  "}

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

  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}],
      "path"=>["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}],
      "path"=>["query getCheese", "missingFieldsCheese"],
    }
    assert_includes(errors, selection_required_error, "finds objects without selections")
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

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