У меня есть модель использования и проекта. У пользователя много проектов. Я пытаюсь понять Graphql.
Я использую драгоценный камень knock для аутентификации. Я передаю current_user в контексте из контроллера graphql.
вот код
module Resolvers
class Projects < GraphQL::Function
type !types[Types::ProjectType]
argument :with_title, types.String
argument :with_description, types.String
# def render_results(title: nil, description: nil, user: nil)
# return user.projects.find_with_title(title) if title
# return user.projects.find_with_description(description) if description
# return user.projects.all if title.nil? && description.nil?
# return user.projects.all
# end
def call(_obj, args, ctx)
title = args['with_title']
description = args['with_description']
binding.pry
# render_results(title: title, description: description, user: ctx[:curent_user])
ctx[:current_user].projects
end
end
end
ctx[:current_user] всегда подходит nil
NoMethodError (undefined method `projects' for nil:NilClass):
Но когда я использую pry для отладки, у него есть текущий пользователь, и я могу без проблем вызвать ctx [: current_user] .projects на нем. Что мне здесь не хватает?
Некоторые моменты, на которые следует обратить внимание. У меня не определен UserType. У меня только ProjectType. Но разве это не должно так работать?





Может быть, есть экземпляр, где
ctx[:user_account]равен нулю. Когда вы используете binding.pry, выполнениеcontinueвозвращает вас к pry? Может поможет переписать как:ctx[:current_user].projects; rescue; binding.pry