rmosolgo / graphiql-rails

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

Question about request header configuration with initializer #82

Closed mattduboismatt closed 7 months ago

mattduboismatt commented 4 years ago

Hello! I've attempted to set a header with the initializer:

# config/initializers/graphiql.rb
GraphiQL::Rails.config.headers["Authorization"] = -> (_context) { "here" }

My graphql endpoint looks like this:

# app/controllers/application_controller.rb
# omitting the rest of the file...
  def graphql
    puts "*"*50
    puts request.headers["Authorization"]
    puts "*"*50
  end

Server log when sending the request via GraphiQL:

Started POST "/graphql" for ::1 at 2020-03-31 15:46:13 -0700
Processing by ApplicationController#graphql as */*
  Parameters: {"query"=>"", "variables"=>"null", "operationName"=>nil, "application"=>{"query"=>"", "variables"=>"null", "operationName"=>nil}}
**************************************************

**************************************************
No template found for ApplicationController#graphql, rendering head :no_content

Do I need to invoke the config? Something else? The header is nil. This is a new Rails app with the following versions: Rails: 6.0.2.2 Ruby: 2.7.0 graphiql-rails: 1.7

rmosolgo commented 7 months ago

Hey, sorry you ran into trouble with this! I hope you found something that works for you. I just tried it out again on the latest graphiql-rails and rails and it seemed to work properly.

One thing to remember is that you have to restart your server if you modify initializers.

If anyone runs into this again, please open a new issue.