In the query_type.rb file, I created a field user with the resolver function, but when I try to execute the query on GraphiQL, the error appear in the server log.
You can see the illustration screenshot below:
Predefined User Type

Resolver Function and Field of User

Error in server log

p/s: I've already had a Active Record Model user.rb in models folder
You can call
::User.find(id)
Yes, I agree with @askn's solution.
This is a consequence of how Ruby looks up constants (like User). First, it looks in the current module nesting, and if it finds something, uses that. So:
module Types
User # => will look for Types::User
def some_method
User # => will look for Types::User
end
end
And it will only go to the top-level ::User if Types::User is _not_ found.
So, if you want to access a top-level constant, you have to prefix it with ::, so that Ruby knows you want a top-level constant, not a nested one.
@rmosolgo @askn Many thanks, you guys saved my day
Most helpful comment
Yes, I agree with @askn's solution.
This is a consequence of how Ruby looks up constants (like
User). First, it looks in the current module nesting, and if it finds something, uses that. So:And it will only go to the top-level
::UserifTypes::Useris _not_ found.So, if you want to access a top-level constant, you have to prefix it with
::, so that Ruby knows you want a top-level constant, not a nested one.