Sha256: d5eecfd55eabcc2a7bef58b6cdad575a30822d968ca994fa4eb93954b5a44d6f

Contents?: true

Size: 1.14 KB

Versions: 11

Compression:

Stored size: 1.14 KB

Contents

require "spec_helper"

describe GraphQL::Schema do
  let(:schema) { DummySchema }

  describe "#rescue_from" do
    let(:rescue_middleware) { schema.middleware.first }

    it "adds handlers to the rescue middleware" do
      assert_equal(1, rescue_middleware.rescue_table.length)
      # normally, you'd use a real class, not a symbol:
      schema.rescue_from(:error_class) { "my custom message" }
      assert_equal(2, rescue_middleware.rescue_table.length)
    end
  end

  describe "#subscription" do
    it "calls fields on the subscription type" do
      res = schema.execute("subscription { test }")
      assert_equal("Test", res["data"]["test"])
    end
  end

  describe "#resolve_type" do
    describe "when the return value is nil" do
      it "returns nil" do
        result = StarWarsSchema.resolve_type(123, nil)
        assert_equal(nil, result)
      end
    end

    describe "when the return value is not a BaseType" do
      it "raises an error " do
        err = assert_raises(RuntimeError) {
          StarWarsSchema.resolve_type(:test_error, nil)
        }
        assert_includes err.message, "not_a_type (Symbol)"
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
graphql-0.18.15 spec/graphql/schema_spec.rb
graphql-0.18.14 spec/graphql/schema_spec.rb
graphql-0.18.13 spec/graphql/schema_spec.rb
graphql-0.18.12 spec/graphql/schema_spec.rb
graphql-0.18.11 spec/graphql/schema_spec.rb
graphql-0.18.10 spec/graphql/schema_spec.rb
graphql-0.18.9 spec/graphql/schema_spec.rb
graphql-0.18.8 spec/graphql/schema_spec.rb
graphql-0.18.7 spec/graphql/schema_spec.rb
graphql-0.18.6 spec/graphql/schema_spec.rb
graphql-0.18.5 spec/graphql/schema_spec.rb