Sha256: 189cb9ca7e6d5766e1d72808ecddd646bf30a880ce98c51d980a5bdb76cf64df

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true
require "spec_helper"
require "generators/graphql/object_generator"

class GraphQLGeneratorsObjectGeneratorTest < BaseGeneratorTest
  tests Graphql::Generators::ObjectGenerator

  test "it generates fields with types" do
    commands = [
      # GraphQL-style:
      ["Bird", "wingspan:Int!", "foliage:[Color]"],
      # Ruby-style:
      ["BirdType", "wingspan:!Integer", "foliage:[Types::ColorType]"],
      # Mixed
      ["BirdType", "wingspan:!Int", "foliage:[Color]"],
    ]

    expected_content = <<-RUBY
class Types::BirdType < Types::BaseObject
  field :wingspan, Integer, null: false
  field :foliage, [Types::ColorType], null: true
end
RUBY

    commands.each do |c|
      prepare_destination
      run_generator(c)
      assert_file "app/graphql/types/bird_type.rb", expected_content
    end
  end

  test "it generates classifed file" do
    run_generator(["page"])
    assert_file "app/graphql/types/page_type.rb", <<-RUBY
class Types::PageType < Types::BaseObject
end
RUBY
  end

  test "it makes Relay nodes" do
    run_generator(["Page", "--node"])
    assert_file "app/graphql/types/page_type.rb", <<-RUBY
class Types::PageType < Types::BaseObject
  implements GraphQL::Relay::Node.interface
end
RUBY
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
graphql-1.8.6 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.5 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.4 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.3 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.2 spec/generators/graphql/object_generator_spec.rb