1

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?

suyesh
  • 530
  • 7
  • 23
  • Maybe there instance where `ctx[:user_account]` is nil. When you use binding.pry, does executing `continue` take you back to pry? May help to rewrite as: `ctx[:current_user].projects; rescue; binding.pry` – Aaron Breckenridge Aug 23 '18 at 14:00

0 Answers0