Sha256: 9de3ac4798f91af847d8135258eea7d890c80e6eee8b44ed60c544247e60885a

Contents?: true

Size: 936 Bytes

Versions: 23

Compression:

Stored size: 936 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) }
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

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