Sha256: 083428d1ebb794c073e08820e55a82db78d8bc7d2888b2d67a029ba0eca1f6fd

Contents?: true

Size: 1.28 KB

Versions: 42

Compression:

Stored size: 1.28 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:!types.Int", "foliage:types[Types::ColorType]"],
      # Mixed
      ["BirdType", "wingspan:!Int", "foliage:types[Color]"],
    ]

    expected_content = <<-RUBY
Types::BirdType = GraphQL::ObjectType.define do
  name "Bird"
  field :wingspan, !types.Int
  field :foliage, types[Types::ColorType]
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
Types::PageType = GraphQL::ObjectType.define do
  name "Page"
end
RUBY
  end

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

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
graphql-1.8.1 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.0 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.0.pre11 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.0.pre10 spec/generators/graphql/object_generator_spec.rb
graphql-1.7.14 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.0.pre9 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.0.pre8 spec/generators/graphql/object_generator_spec.rb
graphql-1.7.13 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.0.pre7 spec/generators/graphql/object_generator_spec.rb
graphql-1.7.12 spec/generators/graphql/object_generator_spec.rb
graphql-1.7.11 spec/generators/graphql/object_generator_spec.rb
graphql-1.7.10 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.0.pre6 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.0.pre5 spec/generators/graphql/object_generator_spec.rb
graphql-1.7.9 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.0.pre4 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.0.pre3 spec/generators/graphql/object_generator_spec.rb
graphql-1.7.8 spec/generators/graphql/object_generator_spec.rb
graphql-1.8.0.pre2 spec/generators/graphql/object_generator_spec.rb
graphql-1.7.7 spec/generators/graphql/object_generator_spec.rb