Sha256: 981431327029f5091e52123263986fce46578223711c55ba4f83b453cfa54200

Contents?: true

Size: 1.15 KB

Versions: 18

Compression:

Stored size: 1.15 KB

Contents

require_dependency 'graphql_devise/application_controller'

module GraphqlDevise
  class GraphqlController < ApplicationController
    def auth
      result = if params[:_json]
        GraphqlDevise::Schema.multiplex(
          params[:_json].map do |param|
            { query: param[:query] }.merge(execute_params(param))
          end
        )
      else
        GraphqlDevise::Schema.execute(params[:query], execute_params(params))
      end

      render json: result unless performed?
    end

    attr_accessor :client_id, :token, :resource

    private

    def execute_params(item)
      {
        operation_name: item[:operationName],
        variables:      ensure_hash(item[:variables]),
        context:        { controller: self }
      }
    end

    def ensure_hash(ambiguous_param)
      case ambiguous_param
      when String
        if ambiguous_param.present?
          ensure_hash(JSON.parse(ambiguous_param))
        else
          {}
        end
      when Hash, ActionController::Parameters
        ambiguous_param
      when nil
        {}
      else
        raise ArgumentError, "Unexpected parameter: #{ambiguous_param}"
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
graphql_devise-0.11.4 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.11.3 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.11.2 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.11.1 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.11.0 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.10.1 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.10.0 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.9.2 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.9.1 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.9.0 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.8.1 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.8.0 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.7.0 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.6.0 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.5.0 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.4.1 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.4.0 app/controllers/graphql_devise/graphql_controller.rb
graphql_devise-0.3.0 app/controllers/graphql_devise/graphql_controller.rb