Sha256: fe21d18665706be2fa2ea98c97de62ceb2c7a5d0fd4898c84c9389f22a8b03af

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'spec_helper'

describe GraphQL::Validations::FieldsAreDefinedOnType do
  let(:document) { GraphQL.parse("
    query getCheese($sourceVar: DairyAnimal!) {
      notDefinedField { name }
      cheese(id: 1) { nonsenseField, flavor }
      fromSource(source: COW) { bogusField }
    }

    fragment cheeseFields on Cheese { fatContent, hogwashField }
  ")}

  let(:validator) { GraphQL::Validator.new(schema: DummySchema, validators: [GraphQL::Validations::FieldsAreDefinedOnType]) }
  let(:errors) { validator.validate(document) }
  it "finds fields that are requested on types that don't have that field" do
    expected_errors = [
      "Field 'notDefinedField' doesn't exist on type 'Query'",  # from query root
      "Field 'nonsenseField' doesn't exist on type 'Cheese'",   # from another field
      "Field 'bogusField' doesn't exist on type 'Cheese'",      # from a list
      "Field 'hogwashField' doesn't exist on type 'Cheese'",    # from a fragment
    ]
    assert_equal(expected_errors, errors)
  end

  it 'finds invalid fields on interfaces'
  it 'finds invalid fields on unions'
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql-0.1.0 spec/graph_ql/validations/fields_are_defined_on_type_spec.rb