Sha256: 0b49bfc3b66fd4a224944c0f0a15aa12d64b5dca179dc020c3472a964d1392de

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

describe GraphQL::Schema::TypeReducer do
  it 'finds types from a single type and its fields' do
    reducer = GraphQL::Schema::TypeReducer.new(CheeseType, {})
    expected = {
      "Cheese" => CheeseType,
      "Int" => GraphQL::INT_TYPE,
      "String" => GraphQL::STRING_TYPE,
      "DairyAnimal" => DairyAnimalEnum,
      "Float" => GraphQL::FLOAT_TYPE,
      "Edible" => EdibleInterface,
      "Milk" => MilkType,
      "ID" => GraphQL::ID_TYPE,
      "AnimalProduct" => AnimalProductInterface,
    }
    assert_equal(expected.keys, reducer.result.keys)
    assert_equal(expected, reducer.result)
  end

  it 'finds type from arguments' do
    reducer = GraphQL::Schema::TypeReducer.new(QueryType, {})
    assert_equal(DairyProductInputType, reducer.result["DairyProductInput"])
  end

  describe 'when a type is invalid' do
    let(:invalid_type) {
      GraphQL::ObjectType.define do
        name "InvalidType"
        field :someField
      end
    }

    it 'raises an InvalidTypeError' do
      reducer = GraphQL::Schema::TypeReducer.new(invalid_type, {})
      assert_raises(GraphQL::Schema::InvalidTypeError) { reducer.result }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
graphql-0.7.1 spec/graphql/schema/type_reducer_spec.rb
graphql-0.7.0 spec/graphql/schema/type_reducer_spec.rb
graphql-0.6.2 spec/graphql/schema/type_reducer_spec.rb
graphql-0.6.1 spec/graphql/schema/type_reducer_spec.rb
graphql-0.6.0 spec/graphql/schema/type_reducer_spec.rb