class GraphiQL::Rails::Config
Constants
- CSRF_TOKEN_HEADER
- DEFAULT_HEADERS
Attributes
@example Adding a header to the request
config.headers["My-Header"] = -> (view_context) { "My-Value" }
@return [Hash<String => Proc>] Keys are headers to include in GraphQL requests, values are ‘->(view_context) { … }` procs to determin values
Public Class Methods
Source
# File lib/graphiql/rails/config.rb, line 20 def initialize(query_params: false, initial_query: nil, title: nil, logo: nil, csrf: true, headers: DEFAULT_HEADERS, input_value_deprecation: false) @query_params = query_params @headers = headers.dup @initial_query = initial_query @title = title @logo = logo @csrf = csrf @input_value_deprecation = input_value_deprecation end
Public Instance Methods
Source
# File lib/graphiql/rails/config.rb, line 31 def resolve_headers(view_context) all_headers = DEFAULT_HEADERS.merge(headers) if csrf all_headers = all_headers.merge(CSRF_TOKEN_HEADER) end all_headers.each_with_object({}) do |(key, value), memo| header_value = value.call(view_context) memo[key] = header_value if !header_value.nil? end end
Call defined procs, add CSRF token if specified