Sha256: 111bdfc07d9f22cc5b2ab8e1b0ab7fa513a7bd37388ea001b721874eebeafe00

Contents?: true

Size: 1.23 KB

Versions: 21

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

# frozen_string_literal: true'

require_relative 'resolvers_generator'

module Ibrain
  module Graphql
    # TODO: What other options should be supported?
    #
    # @example Generate a `GraphQL::Schema::Resolver` by name
    #     rails g graphql:resolver PostsResolver
    class ResolverGenerator < ResolversGenerator
      source_root File.expand_path('templates', __dir__)

      def create_resolver_file
        if @behavior == :revoke
          log :gsub, "#{options[:directory]}/types/query_type.rb"
        else
          create_resolver_root_type
        end

        if options[:model].present?
          system("bundle exec rails generate ibrain:graphql:object #{options[:model].underscore}")
        end

        template "resolver.erb", "#{options[:directory]}/resolvers/#{file_name}.rb"
        return unless ::Ibrain::Config.is_auto_append_mutation

        in_root do
          gsub_file "#{options[:directory]}/types/query_type.rb", /  \# TODO: Add Resolvers as fields\s*\n/m, ""
          inject_into_file "#{options[:directory]}/types/query_type.rb", "\n    field :#{field_name}, resolver: Resolvers::#{resolver_name} \n  ", before: "end\nend", verbose: true, force: true
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ibrain-core-0.5.15 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.13 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.12 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.10 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.9 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.8 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.7 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.6 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.5 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.4 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.3 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.2 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.1 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.5.0 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.4.9 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.4.8 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.4.7 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.4.5 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.4.4 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.4.3 lib/generators/ibrain/graphql/resolver_generator.rb