Sha256: 15a61f270f30e93f6cde23bc0d9cc8a3630de42278d07189071c7d68c647cf93

Contents?: true

Size: 1.82 KB

Versions: 36

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Schema::Member::TypeSystemHelpers do
  let(:object) {
    Class.new(GraphQL::Schema::Object) do
      graphql_name "Thing"

      field :int, Integer, null: true
      field :int2, Integer, null: false
      field :int_list, [Integer], null: true
      field :int_list2, [Integer], null: false
    end
  }

  let(:int_field) { object.fields["int"] }
  let(:int2_field) { object.fields["int2"] }
  let(:int_list_field) { object.fields["intList"] }
  let(:int_list2_field) { object.fields["intList2"] }

  describe "#list?" do
    it "is true for lists, including non-null lists, otherwise false" do
      assert int_list_field.type.list?
      assert int_list2_field.type.list?
      refute int_field.type.list?
      refute int2_field.type.list?
    end
  end

  describe "#non_null?" do
    it "is true for required types" do
      assert int2_field.type.non_null?
      assert int_list2_field.type.non_null?
      refute int_field.type.non_null?
      refute int_list_field.type.non_null?
    end
  end

  describe "#kind" do
    let(:pairs) {{
      GraphQL::Schema::Object => "OBJECT",
      GraphQL::Schema::Union => "UNION",
      GraphQL::Schema::Interface => "INTERFACE",
      GraphQL::Schema::Enum => "ENUM",
      GraphQL::Schema::InputObject => "INPUT_OBJECT",
      GraphQL::Schema::Scalar => "SCALAR",
    }}
    it "returns the TypeKind instance" do
      pairs.each do |type_class, type_kind_name|
        type = if type_class.is_a?(Class)
          Class.new(type_class)
        else
          Module.new { include(type_class) }
        end

        assert_equal type_kind_name, type.kind.name
      end

      assert_equal "LIST", GraphQL::Schema::Object.to_list_type.kind.name
      assert_equal "NON_NULL", GraphQL::Schema::Object.to_non_null_type.kind.name
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
graphql-1.8.13 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.12 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.9.0.pre1 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.11 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.10 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.9 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.8 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.7 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.6 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.5 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.4 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.3 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.2 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.1 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.0 spec/graphql/schema/member/type_system_helpers_spec.rb
graphql-1.8.0.pre11 spec/graphql/schema/member/type_system_helpers_spec.rb