Sha256: 0df1b8f63ac7a0aadb2e1ec0965f847df1ef35a3da3ce71e47d39b125d555a3b
Contents?: true
Size: 1.11 KB
Versions: 3
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true module GraphqlDevise module AuthControllerMethods extend ActiveSupport::Concern def auth result = if params[:_json] Schema.multiplex( params[:_json].map do |param| { query: param[:query] }.merge(execute_params(param)) end ) else 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
3 entries across 3 versions & 1 rubygems