Sha256: 836e4a10c4f2803c1d325624a63fe07e2702763fb0560fa9c95369c756210cfe

Contents?: true

Size: 939 Bytes

Versions: 109

Compression:

Stored size: 939 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", "#{options[:directory]}/types/#{type_file_name}.rb"
      end

      private

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

Version data entries

109 entries across 109 versions & 2 rubygems

Version Path
graphql-1.11.12 lib/generators/graphql/union_generator.rb
graphql-1.11.11 lib/generators/graphql/union_generator.rb
graphql-1.12.25 lib/generators/graphql/union_generator.rb
graphql_cody-1.13.0 lib/generators/graphql/union_generator.rb
graphql-1.12.24 lib/generators/graphql/union_generator.rb
graphql-1.13.6 lib/generators/graphql/union_generator.rb
graphql-1.13.5 lib/generators/graphql/union_generator.rb
graphql-1.13.4 lib/generators/graphql/union_generator.rb
graphql-1.13.3 lib/generators/graphql/union_generator.rb
graphql-1.12.23 lib/generators/graphql/union_generator.rb
graphql-1.13.2 lib/generators/graphql/union_generator.rb
graphql-1.13.1 lib/generators/graphql/union_generator.rb
graphql-1.12.22 lib/generators/graphql/union_generator.rb
graphql-1.13.0 lib/generators/graphql/union_generator.rb
graphql-1.12.21 lib/generators/graphql/union_generator.rb
graphql-1.12.20 lib/generators/graphql/union_generator.rb
graphql-1.12.19 lib/generators/graphql/union_generator.rb
graphql-1.11.10 lib/generators/graphql/union_generator.rb
graphql-1.12.18 lib/generators/graphql/union_generator.rb
graphql-1.11.9 lib/generators/graphql/union_generator.rb