Class: GraphiQL::Rails::Config
- Inherits:
-
Object
- Object
- GraphiQL::Rails::Config
- Defined in:
- lib/graphiql/rails/config.rb
Constant Summary collapse
- DEFAULT_HEADERS =
{ 'Content-Type' => ->(_) { 'application/json' }, }
- CSRF_TOKEN_HEADER =
{ "X-CSRF-Token" => -> (view_context) { view_context.form_authenticity_token } }
Instance Attribute Summary collapse
-
#csrf ⇒ Object
Returns the value of attribute csrf.
-
#header_editor_enabled ⇒ Object
Returns the value of attribute header_editor_enabled.
-
#headers ⇒ Hash<String => Proc>
Keys are headers to include in GraphQL requests, values are ‘->(view_context) { … }` procs to determin values.
-
#initial_query ⇒ Object
Returns the value of attribute initial_query.
-
#input_value_deprecation ⇒ Object
Returns the value of attribute input_value_deprecation.
-
#logo ⇒ Object
Returns the value of attribute logo.
-
#query_params ⇒ Object
Returns the value of attribute query_params.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(query_params: false, initial_query: nil, title: nil, logo: nil, csrf: true, headers: DEFAULT_HEADERS, input_value_deprecation: false) ⇒ Config
constructor
A new instance of Config.
-
#resolve_headers(view_context) ⇒ Object
Call defined procs, add CSRF token if specified.
Constructor Details
#initialize(query_params: false, initial_query: nil, title: nil, logo: nil, csrf: true, headers: DEFAULT_HEADERS, input_value_deprecation: false) ⇒ Config
Returns a new instance of Config.
20 21 22 23 24 25 26 27 28 |
# 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 |
Instance Attribute Details
#csrf ⇒ Object
Returns the value of attribute csrf.
10 11 12 |
# File 'lib/graphiql/rails/config.rb', line 10 def csrf @csrf end |
#header_editor_enabled ⇒ Object
Returns the value of attribute header_editor_enabled.
10 11 12 |
# File 'lib/graphiql/rails/config.rb', line 10 def header_editor_enabled @header_editor_enabled end |
#headers ⇒ Hash<String => Proc>
Returns Keys are headers to include in GraphQL requests, values are ‘->(view_context) { … }` procs to determin values.
8 9 10 |
# File 'lib/graphiql/rails/config.rb', line 8 def headers @headers end |
#initial_query ⇒ Object
Returns the value of attribute initial_query.
10 11 12 |
# File 'lib/graphiql/rails/config.rb', line 10 def initial_query @initial_query end |
#input_value_deprecation ⇒ Object
Returns the value of attribute input_value_deprecation.
10 11 12 |
# File 'lib/graphiql/rails/config.rb', line 10 def input_value_deprecation @input_value_deprecation end |
#logo ⇒ Object
Returns the value of attribute logo.
10 11 12 |
# File 'lib/graphiql/rails/config.rb', line 10 def logo @logo end |
#query_params ⇒ Object
Returns the value of attribute query_params.
10 11 12 |
# File 'lib/graphiql/rails/config.rb', line 10 def query_params @query_params end |
#title ⇒ Object
Returns the value of attribute title.
10 11 12 |
# File 'lib/graphiql/rails/config.rb', line 10 def title @title end |
Instance Method Details
#resolve_headers(view_context) ⇒ Object
Call defined procs, add CSRF token if specified
31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |