I have a use and project model. User has many projects. I am trying to understand Graphql.
I am using knock gem to authenticate. I am passing current_user in context from the graphql controller.
here is the code
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]
always comes up nil
NoMethodError (undefined method `projects' for nil:NilClass):
But when i use pry to debug, it does have current user and i can call ctx[:current_user].projects on it with no issue. What am i missing here?
Some points to note. I do not have UserType defined. I just have ProjectType. But isn't it supposed to work like this too?