Sha256: 8dfa851aa299dc56e9f6e7b7a2424d1a28ff75a2294fb770e87f2b80c221328d

Contents?: true

Size: 1.22 KB

Versions: 29

Compression:

Stored size: 1.22 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].downcase}")
        end

        template "resolver.erb", "#{options[:directory]}/resolvers/#{file_name}.rb"

        sentinel = /class .*QueryType\s*<\s*[^\s]+?\n/m
        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", "    field :#{field_name}, resolver: Resolvers::#{resolver_name}\n\n", after: sentinel, verbose: false, force: false
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
ibrain-core-0.3.6.pre.rc.1 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.6 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.5 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.4 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.3.pre.rc.2 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.3.pre.rc.1 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.3 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.2.pre.rc.4 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.2.pre.rc.3 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.2.pre.rc lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.2 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.1 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.3.0 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.2.9 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.2.8 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.2.7 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.2.6 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.2.5 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.2.4 lib/generators/ibrain/graphql/resolver_generator.rb
ibrain-core-0.2.3 lib/generators/ibrain/graphql/resolver_generator.rb