Sha256: ed5bbb00b2f2d567ffd25f6164d3d152c4e49bae43cb95d9afcc80f047cc3466

Contents?: true

Size: 1.51 KB

Versions: 24

Compression:

Stored size: 1.51 KB

Contents

require "spec_helper"

describe GraphQL::ObjectType do
  let(:type) { CheeseType }

  it "has a name" do
    assert_equal("Cheese", type.name)
    type.name = "Fromage"
    assert_equal("Fromage", type.name)
    type.name = "Cheese"
  end

  it "has a description" do
    assert_equal(22, type.description.length)
  end

  it "may have interfaces" do
    assert_equal([EdibleInterface, AnimalProductInterface, LocalProductInterface], type.interfaces)
  end

  it "accepts fields definition" do
    last_produced_dairy = GraphQL::Field.define(name: :last_produced_dairy, type: DairyProductUnion)
    cow_type = GraphQL::ObjectType.define(name: "Cow", fields: [last_produced_dairy])
    assert_equal([last_produced_dairy], cow_type.fields)
  end

  describe '#get_field ' do
    it "exposes fields" do
      field = type.get_field("id")
      assert_equal(GraphQL::TypeKinds::NON_NULL, field.type.kind)
      assert_equal(GraphQL::TypeKinds::SCALAR, field.type.of_type.kind)
    end

    it "exposes defined field property" do
      field_without_prop = CheeseType.get_field("flavor")
      field_with_prop = CheeseType.get_field("fatContent")
      assert_equal(field_without_prop.property, nil)
      assert_equal(field_with_prop.property, :fat_content)
    end

    it "looks up from interfaces" do
      field_from_self = CheeseType.get_field("fatContent")
      field_from_iface = MilkType.get_field("fatContent")
      assert_equal(field_from_self.property, :fat_content)
      assert_equal(field_from_iface.property, nil)
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
graphql-1.2.6 spec/graphql/object_type_spec.rb
graphql-1.2.5 spec/graphql/object_type_spec.rb
graphql-1.2.4 spec/graphql/object_type_spec.rb
graphql-1.2.3 spec/graphql/object_type_spec.rb
graphql-1.2.2 spec/graphql/object_type_spec.rb
graphql-1.2.1 spec/graphql/object_type_spec.rb
graphql-1.2.0 spec/graphql/object_type_spec.rb
graphql-1.1.0 spec/graphql/object_type_spec.rb
graphql-1.0.0 spec/graphql/object_type_spec.rb
graphql-0.19.4 spec/graphql/object_type_spec.rb
graphql-0.19.3 spec/graphql/object_type_spec.rb
graphql-0.19.2 spec/graphql/object_type_spec.rb
graphql-0.19.1 spec/graphql/object_type_spec.rb
graphql-0.19.0 spec/graphql/object_type_spec.rb
graphql-0.18.15 spec/graphql/object_type_spec.rb
graphql-0.18.14 spec/graphql/object_type_spec.rb
graphql-0.18.13 spec/graphql/object_type_spec.rb
graphql-0.18.12 spec/graphql/object_type_spec.rb
graphql-0.18.11 spec/graphql/object_type_spec.rb
graphql-0.18.10 spec/graphql/object_type_spec.rb