Попытка получить current_user в резольвере
У меня есть модель использования и проекта. У пользователя много проектов. Я пытаюсь понять Graphql.
Я использую камень для аутентификации. Я передаю 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. Но разве это не должно работать так же?