rmosolgo / graphiql-rails

Mount the GraphiQL query editor in a Rails app
MIT License
447 stars 137 forks source link

Your application has sessions disabled #99

Closed robert-damoc closed 2 years ago

robert-damoc commented 2 years ago

Hi. I am trying to upgrade rails from 6.1 to 7.0.2, and I have an issue with this gem on the new version:

ActionView::Template::Error (Your application has sessions disabled. To write to the session you must first configure a session store):
    11:       graphql_endpoint_path: graphql_endpoint_path,
    12:       initial_query: GraphiQL::Rails.config.initial_query,
    13:       logo: GraphiQL::Rails.config.logo,
    14:       headers: GraphiQL::Rails.config.resolve_headers(self),
    15:       query_params: GraphiQL::Rails.config.query_params
    16:     } %>
    17:   </body>

actionpack (7.0.2.3) lib/action_dispatch/request/session.rb:253:in `load_for_write!'
actionpack (7.0.2.3) lib/action_dispatch/request/session.rb:151:in `[]='
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:449:in `real_csrf_token'
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:467:in `csrf_token_hmac'
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:461:in `global_csrf_token'
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:370:in `masked_authenticity_token'
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:357:in `form_authenticity_token'
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:107:in `form_authenticity_token'
graphiql-rails (1.8.0) lib/graphiql/rails/config.rb:17:in `block in <class:Config>'
graphiql-rails (1.8.0) lib/graphiql/rails/config.rb:38:in `block in resolve_headers'
graphiql-rails (1.8.0) lib/graphiql/rails/config.rb:37:in `each'
graphiql-rails (1.8.0) lib/graphiql/rails/config.rb:37:in `each_with_object'
graphiql-rails (1.8.0) lib/graphiql/rails/config.rb:37:in `resolve_headers'
graphiql-rails (1.8.0) app/views/graphiql/rails/editors/show.html.erb:14

Tried pretty much everything I was able to find online (not too many things out there tho). Did anyone see this issue before or any ideas on how to make it work?

Related versions:

ruby 2.7.4
rails 7.0.2.3
graphql 2.0.2
graphiql-rails 1.8.0
robert-damoc commented 2 years ago

Found the issue. It seems that before, we had in application.rb

config.session_store :disabled

To make it work, had to add the following line in development.rb

config.session_store :cookie_store, key: "_sample_app_session", domain: :all