Module: GraphqlDevise::RouteMounter

Defined in:
lib/graphql_devise/route_mounter.rb

Instance Method Summary collapse

Instance Method Details

#mount_graphql_devise_for(resource, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/graphql_devise/route_mounter.rb', line 3

def mount_graphql_devise_for(resource, options = {})
  routing = 'graphql_devise/graphql#auth'

  if (base_controller = options.delete(:base_controller))
    new_controller = GraphqlDevise.const_set("#{resource}AuthController", Class.new(base_controller))
    new_controller.include(SetUserByToken)
    new_controller.include(AuthControllerMethods)

    routing = "#{new_controller.to_s.underscore.gsub('_controller','')}#auth"
  end

  clean_options = ResourceLoader.new(resource, options, true).call(
    Types::QueryType,
    Types::MutationType
  )

  post clean_options.at, to: routing
  get  clean_options.at, to: routing
end