Ruby on rails 在Ruby on rails中创建graphQL方案时出错
我遇到了这样一个问题,当使用参数实现方案时,出现了一个我不理解的错误。 我是这个框架的新手,不太了解它 这是我的graphql_controller.rbRuby on rails 在Ruby on rails中创建graphQL方案时出错,ruby-on-rails,ruby,heroku,graphql,apollo,Ruby On Rails,Ruby,Heroku,Graphql,Apollo,我遇到了这样一个问题,当使用参数实现方案时,出现了一个我不理解的错误。 我是这个框架的新手,不太了解它 这是我的graphql_controller.rb class GraphqlController < ApplicationController def execute variables = ensure_hash(params[:variables]) query = params[:query] operation_name = params[:op
class GraphqlController < ApplicationController
def execute
variables = ensure_hash(params[:variables])
query = params[:query]
operation_name = params[:operationName]
context = {
user_id: request.headers['USER-ID']
}
result = AtlantWallpapersSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
render json: result
rescue => e
raise e unless Rails.env.development?
handle_error_in_development e
end
private
# Handle form data, JSON body, or a blank value
def ensure_hash(ambiguous_param)
Rails.logger.info(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
def handle_error_in_development(e)
logger.error e.message
logger.error e.backtrace.join("\n")
render json: { error: { message: e.message, backtrace: e.backtrace }, data: {} }, status: 500
end
end
class GraphqlControllere
提高e,除非Rails.env.development?
处理开发中的错误
结束
私有的
#处理表单数据、JSON正文或空值
def确保散列(参数不明确)
Rails.logger.info(参数不明确)
大小写参数
当字符串
是否存在不明确的参数?
确保_散列(JSON.parse(不明确的_参数))
其他的
{}
结束
当散列时,ActionController::Parameters
模糊参数
当零
{}
其他的
raise ArgumentError,“意外参数:#{MUBILIZED_param}”
结束
结束
开发中的def句柄错误(e)
logger.error e.消息
logger.error e.backtrace.join(“\n”)
呈现json:{error:{message:e.message,backtrace:e.backtrace},数据:{},状态:500
结束
结束
这是我在控制台上看到的
NameError(未定义的局部变量或方法“占位符”
#:en}>):