Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

uninitialized constant GraphQL::Pundit #51

Closed
casiodk opened this issue Jun 18, 2018 · 29 comments · Fixed by #52
Closed

uninitialized constant GraphQL::Pundit #51

casiodk opened this issue Jun 18, 2018 · 29 comments · Fixed by #52

Comments

@casiodk
Copy link

casiodk commented Jun 18, 2018

I am following the instructions, but I am getting this error

# Gemfile
gem 'graphql-pundit'

class Types::BaseObject < GraphQL::Schema::Object
  field_class GraphQL::Pundit::Field
end


{
  "status": 500,
  "error": "Internal Server Error",
  "exception": "#<NameError: uninitialized constant GraphQL::Pundit>",
  "traces": {
    "Application Trace": [
      {
        "id": 1,
        "trace": "app/graphql/types/base_object.rb:2:in `<class:BaseObject>'"
      },

I tried to create a new rails app with only gem 'graphql' + 'graphql-pundit' and i get the same error.?

@phyrog
Copy link
Collaborator

phyrog commented Jun 19, 2018

Can you try using gem 'graphql-pundit', '~> 0.7.0' in your Gemfile? I think you still include an old version. Will create a PR to update the readme.

@haizop
Copy link

haizop commented Jun 19, 2018

I am having this same issue. Previously, I was developing off of the class_api branch with no issues. Since changing to gem 'graphql-pundit', '~> 0.7.0' I am receiving this same error. If I switch back to the class_api branch, the error disappears.

@haizop
Copy link

haizop commented Jun 19, 2018

Ok, if I change my Gemfile reference to gem 'graphql-pundit', github: 'ontohub/graphql-pundit' the problem disappears. Is there a problem with the RubyGems distribution?

@phyrog
Copy link
Collaborator

phyrog commented Jun 19, 2018

As far as I can tell, the problem seems to only occur when using bootsnap. Will investigate further.

However, I could not reproduce the issue with a new rails app (using Ruby 2.5.1, Rails 5.2.0, graphql 1.8.0 and graphql-pundit 0.7.0).

@phyrog
Copy link
Collaborator

phyrog commented Jun 19, 2018

Could y'all delete the tmp/cache/bootsnap-compile-cache directory and tmp/cache/bootsnap-load-path-cache and try again?

@haizop
Copy link

haizop commented Jun 19, 2018

I do not use bootsnap.

@phyrog
Copy link
Collaborator

phyrog commented Jun 19, 2018

Are you sure? It's on by default in new rails versions

@haizop
Copy link

haizop commented Jun 19, 2018

I believe bootsnap was only added in Rails 5.2.0. I am on Rails 5.1.6.

@phyrog
Copy link
Collaborator

phyrog commented Jun 19, 2018

Do you have the project online somewhere, so I can have a look?

@haizop
Copy link

haizop commented Jun 19, 2018

Sorry - it is a private repo. Gemfile selection:

ruby '2.5.1'
gem 'rails', '~> 5.1.6'

# API
gem 'graphql', '~> 1.8.3'
# gem 'graphql-pundit', '~> 0.7.0'
gem 'graphql-pundit', github: 'ontohub/graphql-pundit', :ref => '0e2fb3e'
gem 'pundit', '~> 1.1.0'

query type:

class Types::Query < Types::BaseObject

  field :current_user, Types::User, null: true
  field :user, Types::User, null: true do
    argument :id, ID, required: true
    authorize ->(_obj, args, ctx) {
      Api::Graphql::QueryPolicy.new(ctx[:current_user], User.find(args[:id])).user?
    }
  end

  def current_user
    context.current_user
  end

  def user(id:)
    ::User.find(id)
  end
end

Anything in particular you would like to see?

@phyrog
Copy link
Collaborator

phyrog commented Jun 19, 2018

  • When does the error occur? When starting the application or when executing a query?
  • Does the error occur on newly created applications?
  • Does the error occur when running rails c and trying to access GraphQL::Pundit?
  • Can you post the stacktrace of the error (from the Rails output, not the GraphQL response)?

Unfortunately debugging is a bit hard when I can't reproduce the error. Could you create a new project that exhibits this error and upload it, so I can play around with it?

@haizop
Copy link

haizop commented Jun 19, 2018

  1. The error occurs when executing a query.
  2. Don't know, can try to replicate tomorrow.
  3. Yes, the error occurs in the console when trying to access GraphQL::Pundit
NameError (uninitialized constant GraphQL::Pundit):

app/graphql/types/base_object.rb:2:in `<class:BaseObject>'
app/graphql/types/base_object.rb:1:in `<top (required)>'
app/graphql/types/query.rb:1:in `<top (required)>'
app/graphql/spi_schema.rb:2:in `<class:SpiSchema>'
app/graphql/spi_schema.rb:1:in `<top (required)>'
app/controllers/api/graphql_controller.rb:9:in `execute'

@phyrog
Copy link
Collaborator

phyrog commented Jun 19, 2018

What happens when you call require 'graphql-pundit' in the rails console?

@casiodk
Copy link
Author

casiodk commented Jun 19, 2018

I can do it, 2 secs

@casiodk
Copy link
Author

casiodk commented Jun 19, 2018

[1] pry(main)> require 'graphql-pundit'
LoadError: cannot load such file -- graphql-pundit
from /gems/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
[2] pry(main)>

@casiodk
Copy link
Author

casiodk commented Jun 19, 2018

Im using bootsnap and this is run with docker-compose

@casiodk
Copy link
Author

casiodk commented Jun 19, 2018

We can do a screen share if you want to debug

@casiodk
Copy link
Author

casiodk commented Jun 19, 2018

if I open IRB i can require it without any problems

@haizop
Copy link

haizop commented Jun 19, 2018

Thanks @phyrog for your work on this.

@phyrog
Copy link
Collaborator

phyrog commented Jun 19, 2018

@casiodk please try deleting the bootsnap cache as described above. That should fix your problem at least. Since you are using docker-compose, recreating the container should do the trick, unless you have some volume mounted to that particular path.

@haizop can you run the require 'graphql-pundit' in the rails console please? I think you and casiodk have different issues here.

@haizop
Copy link

haizop commented Jun 19, 2018

require 'graphql-pundit'
LoadError: cannot load such file -- graphql-pundit
from /Users/haizop/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'

@casiodk
Copy link
Author

casiodk commented Jun 19, 2018

its the same

{
"status": 500,
"error": "Internal Server Error",
"exception": "#<NameError: uninitialized constant GraphQL::Pundit>",
"traces": {
"Application Trace": [
{
"id": 1,
"trace": "app/graphql/types/base_object.rb:2:in <class:BaseObject>'" }, { "id": 2, "trace": "app/graphql/types/base_object.rb:1:in

'"
},
{
"id": 9,
"trace": "app/graphql/types/query.rb:4:in <module:Types>'" }, { "id": 10, "trace": "app/graphql/types/query.rb:3:in '"
},
{
"id": 17,
"trace": "app/graphql/soundtracktor_api_schema.rb:6:in <class:SoundtracktorApiSchema>'" }, { "id": 18, "trace": "app/graphql/soundtracktor_api_schema.rb:3:in '"
},
{
"id": 26,
"trace": "app/controllers/graphql_controller.rb:17:in `execute'"
}
],
"Framework Trace": [
{

@phyrog
Copy link
Collaborator

phyrog commented Jun 19, 2018

@casiodk Did you recreate the container? If so, could you delete the cache files this time? I just realized that your application is probably mounted into the container, so the tmp directory would be mounted too. Recreating would not work in this case.

@haizop Sorry, I don't think there is much more I can do at this point without a reproduction repo. Let me know when you could reproduce this in a new project and I'll have a look. Btw: requireing work in a non-rails IRB or pry console?

@casiodk
Copy link
Author

casiodk commented Jun 19, 2018

i did this

docker-compose down
docker-compose rm
docker-compose build --no-cache
docker-compose up --force-recreate --remove-orphans

And then inside the container i removed the tmp/cache directory and bundle installed again

@casiodk
Copy link
Author

casiodk commented Jun 19, 2018

If i log into rails console in this app https://github.com/casiodk/graphhhhh

I get this result

(master)$ rails console
Running via Spring preloader in process 1103
Loading development environment (Rails 5.1.6)
2.4.2 :001 > require 'graphql-pundit'
LoadError: cannot load such file -- graphql-pundit
	from (irb):1
2.4.2 :002 >

@phyrog
Copy link
Collaborator

phyrog commented Jun 20, 2018

Oookay, so @haizop was right initially, something definitely went wrong during the gem build. I just downloaded the gem from Rubygems again and noticed that it is completely empty. 🤦‍♂️

I will merge #52 now and make a new release (0.7.1). After that I will retract version 0.7.0 to avoid future problems with this.

@phyrog
Copy link
Collaborator

phyrog commented Jun 20, 2018

Thanks @casiodk and @haizop for bringing this to my attention. I think in the beginning I was still using the version that was built on my PC, which is why I could not reproduce the issue. I tried the graphhhhh repo with a freshly pulled 0.7.1 and the problem has disappeared.

@casiodk
Copy link
Author

casiodk commented Jun 20, 2018

Great, thanks too 👍

@haizop
Copy link

haizop commented Jun 20, 2018

Thanks @phyrog. I really appreciate your attentive maintenance of this gem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants