Sha256: 6b1861af35d4f9dd81b5c20b6d15507732c83d96836498c6e0441be892c1032c

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require 'graphql_rails/controller/action'
require 'graphql_rails/concerns/service'
require 'graphql_rails/controller/action_configuration'
require 'graphql_rails/controller/build_controller_action_resolver/controller_action_resolver'

module GraphqlRails
  class Controller
    # graphql resolver which redirects actions to appropriate controller and controller action
    class BuildControllerActionResolver
      include ::GraphqlRails::Service

      def initialize(route:)
        @route = route
      end

      def call # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
        action = build_action

        Class.new(ControllerActionResolver) do
          graphql_name("ControllerActionResolver#{SecureRandom.hex}")

          type(*action.type_args, **action.type_options)
          description(action.description)
          controller(action.controller)
          controller_action_name(action.name)

          action.arguments.each do |attribute|
            argument(*attribute.input_argument_args, **attribute.input_argument_options)
          end

          def self.inspect
            "ControllerActionResolver(#{controller.name}##{controller_action_name})"
          end
        end
      end

      private

      attr_reader :route

      def build_action
        Action.new(route).tap do |action|
          assert_action(action)
        end
      end

      def assert_action(action)
        action.return_type
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql_rails-2.4.0 lib/graphql_rails/controller/build_controller_action_resolver.rb
graphql_rails-2.3.0 lib/graphql_rails/controller/build_controller_action_resolver.rb