Sha256: b8dd7e0d252508221a09352a07999eee2d3643d9970bff472b382a7cffcafc61

Contents?: true

Size: 868 Bytes

Versions: 107

Compression:

Stored size: 868 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)"

      private

      def graphql_type
        "union"
      end

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

Version data entries

107 entries across 107 versions & 1 rubygems

Version Path
graphql-2.4.8 lib/generators/graphql/union_generator.rb
graphql-2.4.7 lib/generators/graphql/union_generator.rb
graphql-2.4.6 lib/generators/graphql/union_generator.rb
graphql-2.4.5 lib/generators/graphql/union_generator.rb
graphql-2.4.4 lib/generators/graphql/union_generator.rb
graphql-2.4.3 lib/generators/graphql/union_generator.rb
graphql-2.4.2 lib/generators/graphql/union_generator.rb
graphql-2.4.1 lib/generators/graphql/union_generator.rb
graphql-2.4.0 lib/generators/graphql/union_generator.rb
graphql-2.3.20 lib/generators/graphql/union_generator.rb
graphql-2.3.19 lib/generators/graphql/union_generator.rb
graphql-2.3.18 lib/generators/graphql/union_generator.rb
graphql-2.3.17 lib/generators/graphql/union_generator.rb
graphql-2.3.16 lib/generators/graphql/union_generator.rb
graphql-2.3.15 lib/generators/graphql/union_generator.rb
graphql-2.3.14 lib/generators/graphql/union_generator.rb
graphql-2.3.13 lib/generators/graphql/union_generator.rb
graphql-2.3.12 lib/generators/graphql/union_generator.rb
graphql-2.3.11 lib/generators/graphql/union_generator.rb
graphql-2.3.10 lib/generators/graphql/union_generator.rb