Sha256: 3a807d513cfd9e751d8d54e595127603adb2a23ffe835b1b4aab2c0124e3ab70

Contents?: true

Size: 1.61 KB

Versions: 52

Compression:

Stored size: 1.61 KB

Contents

module SOULs
  class Generate < Thor
    desc "resolver_rbs [CLASS_NAME]", "Generate GraphQL Resolver RBS from schema.rb"
    def resolver_rbs(class_name)
      singularized_class_name = class_name.underscore.singularize
      file_path = ""
      Dir.chdir(SOULs.get_mother_path.to_s) do
        file_dir = "./sig/api/app/graphql/resolvers"
        FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
        file_path = "#{file_dir}/#{singularized_class_name}_search.rbs"
        raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)

        File.open(file_path, "w") do |f|
          f.write(<<~TEXT)
            module Resolvers
              class BaseResolver
              end
              class #{singularized_class_name.camelize}Search < BaseResolver
                include SearchObject
                def self.scope: () ?{ () -> nil } -> [Hash[Symbol, untyped]]
                def self.type: (*untyped) -> String
                def self.option: (:filter, type: untyped, with: :apply_filter) -> String
                def self.description: (String) -> String
                def self.types: (*untyped) -> String
                def decode_global_key: (String value) -> Integer
                def apply_filter: (untyped scope, untyped value) -> untyped

                class #{singularized_class_name.camelize}Filter
                  String: String
                  Boolean: Boolean
                  Integer: Integer
                end
              end
            end
          TEXT
        end
      end
      SOULs::Painter.create_file(file_path.to_s)
      file_path
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
souls-2.0.4 lib/souls/cli/generate/resolver_rbs.rb
souls-2.0.3 lib/souls/cli/generate/resolver_rbs.rb
souls-2.0.2 lib/souls/cli/generate/resolver_rbs.rb
souls-2.0.1 lib/souls/cli/generate/resolver_rbs.rb
souls-2.0.0 lib/souls/cli/generate/resolver_rbs.rb
souls-1.23.0 lib/souls/cli/generate/resolver_rbs.rb
souls-1.22.0 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.11 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.10 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.9 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.8 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.7 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.6 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.5 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.4 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.3 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.2 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.1 lib/souls/cli/generate/resolver_rbs.rb
souls-1.21.0 lib/souls/cli/generate/resolver_rbs.rb
souls-1.20.13 lib/souls/cli/generate/resolver_rbs.rb