Sha256: 0b82d5f5cf94eb65c3ba5985a133b10314741c79e3dc3e93577a29fceeeec1d8

Contents?: true

Size: 1.22 KB

Versions: 12

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

describe GraphQL::StaticValidation::FieldsHaveAppropriateSelections do
  let(:document) { GraphQL.parse("
    query getCheese {
      okCheese: cheese(id: 1) { fatContent, similarCheeses(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(:errors) { validator.validate(document) }

  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}]
    }
    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}]
    }
    assert_includes(errors, selection_required_error, 'finds objects without selections')
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
graphql-0.9.3 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-0.9.2 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-0.8.1 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-0.8.0 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-0.7.1 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-0.7.0 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-0.6.2 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-0.6.1 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-0.6.0 spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-0.5.0 spec/graph_ql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-0.4.0 spec/graph_ql/static_validation/rules/fields_have_appropriate_selections_spec.rb
graphql-0.3.0 spec/graph_ql/static_validation/rules/fields_have_appropriate_selections_spec.rb