Sha256: 1e41c06c72bca944003782fde293d94c3f2af3cbfc17404721c5596d34709c25

Contents?: true

Size: 1.64 KB

Versions: 27

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Schema::Union do
  let(:union) { Jazz::PerformingAct }

  describe ".path" do
    it "is the name" do
      assert_equal "PerformingAct", union.path
    end
  end

  describe "type info" do
    it "has some" do
      assert_equal 2, union.possible_types.size
    end
  end

  describe ".to_graphql" do
    it "creates a UnionType" do
      union = Class.new(GraphQL::Schema::Union) do
        possible_types Jazz::Musician, Jazz::Ensemble

        def self.name
          "MyUnion"
        end
      end
      union_type = union.to_graphql
      assert_equal "MyUnion", union_type.name
      assert_equal [Jazz::Musician.to_graphql, Jazz::Ensemble.to_graphql], union_type.possible_types
      assert_nil union_type.resolve_type_proc
    end

    it "can specify a resolve_type method" do
      union = Class.new(GraphQL::Schema::Union) do
        def self.resolve_type(_object, _context)
          "MyType"
        end

        def self.name
          "MyUnion"
        end
      end
      union_type = union.to_graphql
      assert_equal "MyType", union_type.resolve_type_proc.call(nil, nil)
    end
  end

  describe "in queries" do
    it "works" do
      query_str = <<-GRAPHQL
      {
        nowPlaying {
          ... on Musician {
            name
            instrument {
              family
            }
          }
          ... on Ensemble {
            name
          }
        }
      }
      GRAPHQL

      res = Jazz::Schema.execute(query_str)
      expected_data = { "name" => "Bela Fleck and the Flecktones" }
      assert_equal expected_data, res["data"]["nowPlaying"]
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
graphql-1.8.18 spec/graphql/schema/union_spec.rb
graphql-1.9.11 spec/graphql/schema/union_spec.rb
graphql-1.9.10 spec/graphql/schema/union_spec.rb
graphql-1.9.9 spec/graphql/schema/union_spec.rb
graphql-1.9.8 spec/graphql/schema/union_spec.rb
graphql-1.9.7 spec/graphql/schema/union_spec.rb
graphql-1.9.6 spec/graphql/schema/union_spec.rb
graphql-1.9.5 spec/graphql/schema/union_spec.rb
graphql-1.9.4 spec/graphql/schema/union_spec.rb
graphql-1.9.3 spec/graphql/schema/union_spec.rb
graphql-1.9.2 spec/graphql/schema/union_spec.rb
graphql-1.8.17 spec/graphql/schema/union_spec.rb
graphql-1.8.16 spec/graphql/schema/union_spec.rb
graphql-1.9.1 spec/graphql/schema/union_spec.rb
graphql-1.9.0 spec/graphql/schema/union_spec.rb
graphql-1.8.15 spec/graphql/schema/union_spec.rb
graphql-1.9.0.pre4 spec/graphql/schema/union_spec.rb
graphql-1.8.14 spec/graphql/schema/union_spec.rb
graphql-1.9.0.pre3 spec/graphql/schema/union_spec.rb
graphql-1.9.0.pre2 spec/graphql/schema/union_spec.rb