Sha256: e10d21093eadb50432475a8b1a9d5fc209fa7bd97963fca24cf2a119ba59c536

Contents?: true

Size: 925 Bytes

Versions: 28

Compression:

Stored size: 925 Bytes

Contents

# frozen_string_literal: true
require 'generators/graphql/type_generator'

module Graphql
  module Generators
    # Generate a union type by name
    # with the specified member types.
    #
    # ```
    # rails g graphql:union SearchResultType ImageType AudioType
    # ```
    class UnionGenerator < TypeGeneratorBase
      desc "Create a GraphQL::UnionType with the given name and possible types"
      source_root File.expand_path('../templates', __FILE__)

      argument :possible_types,
        type: :array,
        default: [],
        banner: "type type ...",
        desc: "Possible types for this union (expressed as Ruby or GraphQL)"

      def create_type_file
        template "union.erb", "app/graphql/types/#{type_file_name}.rb"
      end

      private

      def normalized_possible_types
        possible_types.map { |t| self.class.normalize_type_expression(t, mode: :ruby) }
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
graphql-1.7.4 lib/generators/graphql/union_generator.rb
graphql-1.7.3 lib/generators/graphql/union_generator.rb
graphql-1.7.2 lib/generators/graphql/union_generator.rb
graphql-1.7.1 lib/generators/graphql/union_generator.rb
graphql-1.7.0 lib/generators/graphql/union_generator.rb
graphql-1.6.8 lib/generators/graphql/union_generator.rb
graphql-1.6.7 lib/generators/graphql/union_generator.rb
graphql-1.6.6 lib/generators/graphql/union_generator.rb
graphql-1.6.5 lib/generators/graphql/union_generator.rb
graphql-1.6.4 lib/generators/graphql/union_generator.rb
graphql-1.5.15 lib/generators/graphql/union_generator.rb
graphql-1.6.3 lib/generators/graphql/union_generator.rb
graphql-1.6.2 lib/generators/graphql/union_generator.rb
graphql-1.6.1 lib/generators/graphql/union_generator.rb
graphql-1.6.0 lib/generators/graphql/union_generator.rb
graphql-1.5.14 lib/generators/graphql/union_generator.rb
graphql-1.5.13 lib/generators/graphql/union_generator.rb
graphql-1.5.7.1 lib/generators/graphql/union_generator.rb
graphql-1.5.12 lib/generators/graphql/union_generator.rb
graphql-1.5.11 lib/generators/graphql/union_generator.rb